MongoDB - How to find all objects within an array?

后端 未结 2 817
夕颜
夕颜 2020-12-12 02:50

I\'m trying to find all elements within an array called programme. The result of running db.base.find({\"programme.title\":\"News\"},{\"programme

2条回答
  •  自闭症患者
    2020-12-12 03:27

    You can achieve with the help of Aggregation as below :

     db.base.aggregate([
        {$unwind : "$programme"},
        {$match : { "programme.title" : "News" } },
       {$group : { "_id" : "$_id" , "programme" : { $push: "$programme" } } }
    ]);
    

提交回复
热议问题