![](/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.