Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find in dictionary by value in Mongo

I have such structure in my Mongo db:

{'_id':'...', 
    'friends': 
        {'id1': {'name1':'value1', 'name2':'value2'},
        'id2': {'name1':'', 'name2':''},
         ...}
}

How can I find element(friend) in this dictionary(friends) by name1(value1)?

like image 570
Rivz Avatar asked Sep 15 '11 13:09

Rivz


1 Answers

db.myCollection.find({"friends.id1.name1":"Sam"})
like image 83
Evgenii Avatar answered Oct 11 '22 20:10

Evgenii