I know this had been asked a million times but I could not find my exact scenario, so here we go:
my data looks like this:
{
"_id" : ObjectId("55bf22a73d64bd3c495adf3d"),
"_data_type" : "questionnaire",
"title" : "Food quality",
"_namespace" : "questionnaire",
"description" : "tell us your opinion",
"created_time" : ISODate("2015-08-03T08:13:27.874Z"),
"questions" : {
"sub_id_1" : {
"o2" : "Bad",
"o1" : "Good",
"_namespace" : "questionnaire::question",
"question" : "How do you rate our food quality"
},
"sub_id_2" : {
"o2" : "Bad",
"o1" : "Good",
"_namespace" : "questionnaire::question",
"question" : "How do you rate the colouring of our dishes "
},
"sub_id_3" : {
"o2" : "I don't care!",
"o1" : "It is greate",
"_namespace" : "questionnaire::question",
"question" : "How do you like our couches"
}
},
"updated_time" : ISODate("2015-08-03T08:20:37.982Z")
}
I want to get all the questions that have "o2" equal "Bad".
I tried the following but no luck.
> db.questionnaire.find({"questions.$.o2": "Bad"})
> db.questionnaire.find({"questions.o2": "Bad"})