开发者

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)?


db.myCollection.find({"friends.id1.name1":"Sam"})


Is this what you mean?

db.dbname.find({name1:'value1'})

If value1 can be in any field, you can try:

db.dbname.find({$or:[{name1:'value1'},{name2:'value1'}]})


If I'm understanding your question correctly You can do this by:

  • db.collection.find({name:'value1'});

Here is a great resource to start learning mongo and various commands from it.

Interactive Mongo Tutorial

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜