sql >> Base de Datos >  >> NoSQL >> MongoDB

distinto con múltiples campos y con condición where en mongodb

Necesitará usar el aggregate consultas para lograrlo. Aquí hay un ejemplo que funcionará en shell (que se puede traducir fácilmente a Mongoose):

db.gpc.aggregate([
    // your where clause: note="test2" and notetwo = "meet2"
    {"$match" : {note:"test2", notetwo:"meet2"}}, 
    // group by key, score to get distinct
    {"$group" : {_id : {key:"$key", score:"$score"}}}, 
    // Clean up the output
    {"$project" : {_id:0, key:"$_id.key", score:"$_id.score"}}
])

Salida:

{ "result" : [ { "key" : "SAGAR33", "score" : 37 } ], "ok" : 1 }