例如这样的数据:
{ "name": "Bob" "friends": [ { "name": "Lucy", "age": 18 }, { "name": "David", "age": 17 } ] }
我希望返回这样一个 list: ["Lucy", "David"]。
["Lucy", "David"]
其实说白了,我需要用这个返回的结果进行二次查询,比如查询 Lucy 和 David 的信息。
学习是最好的投资!
Restrict fields,db.DATA.find({ }, { "name" : 1 })
db.DATA.find({ }, { "name" : 1 })
mongo supports js syntax, so you can use js capabilities to prune data
> db.b.insert({ "name": "Bob", "friends": [ { "name": "Lucy", "age": 18 }, { "name": "David", "age": 17 } ] }) WriteResult({ "nInserted" : 1 }) > db.b.findOne({name:"Bob"}).friends.map( x => x.name ) [ "Lucy", "David" ]
Restrict fields,
db.DATA.find({ }, { "name" : 1 })
mongo supports js syntax, so you can use js capabilities to prune data