有没有办法在mongodb投影中仅返回属性的值?例如,我有一个文档,其中一个属性的值是一个数组。我希望查询返回的对象仅为该数组,而不是
文档:
我希望它返回数组中的值:
有没有办法做到这一点?谢谢。
property:[...]
。例如:文档:
db.test.insert({ name: "Andrew",
attributes: [ { title: "Happy"},
{ title: "Sad" }
]
});
查询:
db.test.find({name: "Andrew"},{attributes:1, "_id":0});
这将返回:
{ "attributes" : [ { "title" : "Happy" }, { "title" : "Sad" } ] }
我希望它返回数组中的值:
[ { title: "Happy"},
{ title: "Sad" }
]
有没有办法做到这一点?谢谢。