so i have the below query that does NOT return anything when it should.
db.food.find({ingredient : {name : {$ne : "Kahlua"}}}); //empty data
However, what i think is its equivalent does output the correct info:
db.food.find({"ingredient.name" : {$ne : "Kahlua"}}); //gives correct data
I tried this using the BrowserShell for the above 2 queries, and it hasn’t given me much problem for simple functions and queries.
No, they are not the same.
is saying “find where the ingredient name is not equal to Kahlua”, whereas…
is saying “find where the ingredient sub object consists of a name property only, where that name is not equal to Kahlua”. So in this case you’re actually performing a search on the whole subject.
Probably far better explained here – dot notation vs subobjects