如何在Mongo DB中选择嵌套数组的属性

时间:2019-04-01 09:41:13

标签: mongodb

我正在做一个项目,有点卡住了。我有以下数据集:


{  
   "_id":"5ca1bce731f866952d372114",
   "Title":"Modern Family",
   "Season":"1",
   "totalSeasons":"10",
   "Episodes":[  
      {  
         "Title":"Pilot",
         "Released":"2009-09-22",
         "Episode":"1",
         "imdbRating":"8.2",
         "imdbID":"tt1444504"
      },
      {  
         "Title":"The Bicycle Thief",
         "Released":"2009-09-30",
         "Episode":"2",
         "imdbRating":"8.2",
         "imdbID":"tt1492032"
      }
]
}

我想显示所有情节,但仅显示Episodes数组中所有元素的字段:Title和Episode。到目前为止,我已经使用以下代码成功打印了情节列表中的所有元素:

db.series.find({},{Episodes:1})

如何过滤情节数组以仅显示其标题和情节?

0 个答案:

没有答案