![](/img/trans.png)
[英]How to copy the elements of an array into an array in a Mongodb document
[英]How to return property of all elements of array inside MongoDB document?
function ObjArray(array){
let newArr = [];
array.foreach(
(obj) => {
let newobj = {title: '', id:''}
newobj.title = obj.title;
newobj.id = obj.id;
newArr.append(newobj);
}
);
return newArr;
}
您可以使用find({})
来获得您的预期结果。 在查找查询中,您需要使用投影阶段。
预期查询
db.collection.find({},{_id:1,"trips.title":1,"trips._id":1});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.