I have a collection with document structure as below:
"_id": {
"userId": "user_id_1"
},
"val": {
"status": 1,
"otherKey": "otherValue"
}
There are two queries I tried to get this document:
db.getCollection('my_collection').find({ "_id" : { "userId" : "user_id_1"} , "val.status" : 1})
and
db.getCollection('my_collection').find({ "_id" : { "userId" : "user_id_1"} , "val" : { "status" : 1}})
The first query returns the document while the second doesn't. I am tying to match status in similar way as I did for the user id. Can someone explain me the difference between the two queries?