We hope that this request will satisfy your requirement, you can get the corresponding result in a single hit db. Just create a query in the aggregate pipeline
db.collection.aggregate([ {$match : { $or : [ {"name" : {$eq :"Thomas"}}, {"sport" : {$eq : "Tennis"}}, {"favoriteColor" : {$eq : "blue"}} ] }}, {$addFields : { rank : {$sum : [ {$cond : [{$and:[{$eq : ["$name", "Thomas"]},{$eq : ["$sport", "Tennis"]},{$eq : ["$favoriteColor", "blue"]}] } , 1, 0]}, {$cond : [{$and:[{$eq : ["$name", "Thomas"]},{$eq : ["$sport", "Tennis"]}] } , 2, 0]}, {$cond : [{$and:[{$eq : ["$name", "Thomas"]}] } , 3, 0]}, ]} }}, {$group:{ _id:null, doc:{$push:'$$ROOT'}, rank:{$max:'$rank'} }}, {$unwind:'$doc'}, {$redact: { $cond: { if: { $eq: [ "$doc.rank", '$rank' ] }, then: "$$KEEP", else: "$$PRUNE" } }}, { $project:{ name:'$doc.name', sport:'$doc.sport', favoriteColor:'$doc.favoriteColor', }} ])
source share