[英]Remove particular object from array in mongoose document (Mongodb)
我必須從文檔“ dsrNote”中的數組中刪除一個元素
其中具有“ _id”:ObjectId(“ 58a5594bb77d2f1dd49e2986”)
{
"_id": ObjectId("58a558efb77d2f1dd49e2983"),
"userId": ObjectId("586356b199248d1517a6758b"),
"dsrNote": [
{
"activity": "ajay kumar dogra",
"_id": ObjectId("58a5594bb77d2f1dd49e2986")
},
{
"activity": "ajay kumar",
"_id": ObjectId("58a55969b77d2f1dd49e2987")
}
],
}
在上面的文檔中,我需要從dsrNote數組中刪除第一個對象
我已經嘗試過了,但是沒有用
collectionName.update({ "userId": "586356b199248d1517a6758b" }, { $pull: { "dsrNote": { "_id": "58a5594bb77d2f1dd49e2986" } } }).exec(function (err, data) {});
您可以嘗試一下,它正在解決我的問題
DSR.update({"userId":req.ID,"dsrNote._id":req.params.id}, { $pull: {"dsrNote": { "_id":req.params.id}}})
.exec(function(err,data){
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.