Query sub documents in array of parent document

前端 未结 1 1686
走了就别回头了
走了就别回头了 2021-01-28 15:25

db.animals

{\'animal\':\'monkey\',
 \'quantity:3
 \'id\' : 001}
{\'animal\':\'pig\',
 \'quantity:5
 \'id\' : 002}
{\'animal\':\'cow\',
 \'quantity:3
 \'id\' : 00         


        
相关标签:
1条回答
  • 2021-01-28 15:35

    There are no joins in MongoDB so you have to do it in two steps.

    In the shell:

    var john = db.people.findOne({person: 'john'})
    db.animals.find({id: {$in: john.have}})
    
    0 讨论(0)
提交回复
热议问题