mongodb查询返回数组中的单个元素

时间:2015-05-18 17:48:48

标签: arrays mongodb

{People:"1","Location":"US","Name":[{"first":"Tom","last":"Brady"},
{"first":"Jack","last":"Sparrow"},{"first":"Haha","last":"OhOh"}]}

我在MongoDB中有一些数据,数据结构是这样的,如何搜索“Tom”并且只返回

 {People:"1","Location":"US","Name":[{"first":"Tom","last":"Brady"}]}

1 个答案:

答案 0 :(得分:1)

db.collectionName.find({"Name.first": "Tom"}, {_id: 0, People: 1, Location: 1, "Name.$": 1});