Você pode querer usar o $cond operador para lidar com isso:
db.items.aggregate([
{"$project":
{
"name": "$name",
"upvotes": "$upvotes",
"downvotes": "$downvotes",
"quality": { $cond: [ { $eq: [ "$downvotes", 0 ] }, "N/A", {"$divide":["$upvotes", "$downvotes"]} ] }
}
},
{"$sort": {"quality":-1}}
]);