Misschien wilt u de $cond gebruiken operator om dit af te handelen:
db.items.aggregate([
{"$project":
{
"name": "$name",
"upvotes": "$upvotes",
"downvotes": "$downvotes",
"quality": { $cond: [ { $eq: [ "$downvotes", 0 ] }, "N/A", {"$divide":["$upvotes", "$downvotes"]} ] }
}
},
{"$sort": {"quality":-1}}
]);