samedi 4 avril 2015

Apply distinct operator based on existing query


Vote count:

0




I want to distinct the name on current query result, How could I do on MongoDB


Query syntax



db_conn.medical_records.find({"$or": [{"symptom_1": "nose allergic"},{"symptom_2": "nose allergic"}]})


Current query result, but not apply distinct on name



{
"id": 1,
"name": "Mary",
"symptom_1": null,
"symptom_2": "nose allergic",
"datetime": "2011-04-02"
},

{
"id": 2,
"name": "Jack",
"symptom_1": "nose allergic",
"symptoms_2": null,
"datetime": "2011-04-02"
},

{
"id": 3,
"name": "Mark",
"symptoms_1": null,
"symptoms_2": "nose allergic",
"datetime": "2010-01-02"
},

{
"id": 4,
"name": "Mark",
"symptoms_1": "nose allergic",
"symptoms_2": "headach",
"datetime": "2015-04-04"
},


Apply distinct operator based on exsisting query


I want to distinct the name on current query result, How could I do on MongoDB


Query syntax



db_conn.medical_records.find({"$or": [{"symptom_1": "nose allergic"},{"symptom_2": "nose allergic"}]})


Current query result, but not apply distinct on name



{
"id": 1,
"name": "Mary",
"symptom_1": null,
"symptom_2": "nose allergic",
"datetime": "2011-04-02"
},

{
"id": 2,
"name": "Jack",
"symptom_1": "nose allergic",
"symptoms_2": null,
"datetime": "2011-04-02"
},

{
"id": 3,
"name": "Jack",
"symptoms_1": null,
"symptoms_2": "nose allergic",
"datetime": "2010-01-02"
},

{
"id": 4,
"name": "Mark",
"symptoms_1": "nose allergic",
"symptoms_2": "headach",
"datetime": "2015-04-04"
}


Expected result



["Mary", "Jack", "Mark"]


asked 27 secs ago

poc

1,269






Apply distinct operator based on existing query

Aucun commentaire:

Enregistrer un commentaire