Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find inside a hash mongodb

Tags:

mongodb

I have this struct in my collection:

{foo : 1, bar : 4, baz : {a : 1, b : 2 ,c : "fafofu"}}

How do I find "a" and "b" inside baz ? It does not works db.my_collection.find({baz : {a : 1, b : 2});

I don't care about if "c" is "fafofu" or "cacocu" does not matters.

like image 700
Mantovani Avatar asked Jan 16 '11 01:01

Mantovani


1 Answers

You can use . to reach into the baz object.

db.my_collection.find({"baz.a" : 1, "baz.b" : 2});
like image 188
Jeff the Bear Avatar answered Oct 03 '22 08:10

Jeff the Bear