5
Mongooseを使用してObjectからIDを持つサブ文書を削除しようとしています。 私はMoongoseで更新プログラムを使用しようとしていましたが、スクリプト「Im:状態:Ok:1」を実行した後、状態「nModified:0」を実行しました。Mongooseを使用してオブジェクト内のサブ文書を削除する方法
Page.update({"subPages._id": req.body.ID}, {"$unset":{"subPages":1}}, function (re,q) {
console.log(q);
});
このスクリプトは、オブジェクトからすべてのサブ文書を削除します。ここで は私のJSONです:
{
"_id" : ObjectId("585a7a7c2ec07b40ecb093d6"),
"name_en" : "Head Page",
"name_nl" : "Head Page",
"slug_en" : "Head-page",
"slug_nl" : "hoofd-menu",
"content_en" : "<p>Easy (and free!) You should check out our premium features.</p>",
"content_nl" : "<p>Easy (and free!) You should check out our premium features.</p>",
"date" : ISODate("2016-12-21T12:50:04.374Z"),
"is_footerMenu" : 0,
"is_headMenu" : 0,
"visible" : 1,
"__v" : 0,
"subPages" : [
{
"content_nl" : "<p>Easy (and free!) You should check out our premium features.</p>",
"content_en" : "<p>Easy (and free!) You should check out our premium features.</p>",
"slug_nl" : "Sub-page",
"slug_en" : "Sub-page",
"name_nl" : "Subpage",
"name_en" : "Subpage",
"date" : ISODate("2016-12-21T14:58:44.733Z"),
"subPages" : [],
"is_footerMenu" : 0,
"is_headMenu" : 0,
"visible" : 1,
"_id" : ObjectId("585a98a46f657b52489087a8")
},
{
"content_nl" : "<p>Easy (and free!) You should check out our premium features.</p>",
"content_en" : "<p>Easy (and free!) You should check out our premium features.</p>",
"slug_nl" : "Subpage",
"slug_en" : "Subpage",
"name_nl" : "Subpage1",
"name_en" : "Subpage1",
"date" : ISODate("2016-12-21T14:58:54.819Z"),
"subPages" : [],
"is_footerMenu" : 0,
"is_headMenu" : 0,
"visible" : 1,
"_id" : ObjectId("585a98ae6f657b52489087a9")
}
]
}
私はID
585a98a46f657b52489087a8
私はそれをどのように行うことができますでサブオブジェクトを削除したいですか?
しました!どうもありがとうございました。私はその長い時間を過ごした。 –