【发布时间】:2014-02-24 15:55:34
【问题描述】:
这是我的结构:
{
"_id" : ObjectId("52ebf3ba71616b871600000c"),
"components" : [
{
"type" : "text",
"text_type" : "subtitle",
"pos_x" : 198.384521484375,
"pos_y" : 114.43489074707031,
"content" : "New subtitle",
"font" : "",
"font_size" : "",
"color" : "",
"bold" : false,
"italic" : false,
"underlined" : false,
"rotation" : 0,
"scale" : 0,
"custom_css" : "",
"_id" : ObjectId("52ebf3c171616b871600000d")
},
{
"type" : "text",
"text_type" : "title",
"pos_x" : 198.384521484375,
"pos_y" : 114.43489074707031,
"content" : "New title",
"font" : "",
"font_size" : "",
"color" : "",
"bold" : false,
"italic" : false,
"underlined" : false,
"rotation" : 0,
"scale" : 0,
"custom_css" : "",
"_id" : ObjectId("52ebf3c371616b871600000e")
},
{
"type" : "text",
"text_type" : "title",
"pos_x" : 279.32373046875,
"pos_y" : 265.3794403076172,
"content" : "New title",
"font" : "",
"font_size" : "",
"color" : "",
"bold" : false,
"italic" : false,
"underlined" : false,
"rotation" : 0,
"scale" : 0,
"custom_css" : "",
"_id" : ObjectId("52ebf44471616b871600000f")
},
{
"type" : "text",
"text_type" : "subtitle",
"pos_x" : 55.32373046875,
"pos_y" : 35.37944030761719,
"content" : "New subtitle",
"font" : "",
"font_size" : "",
"color" : "",
"bold" : false,
"italic" : false,
"underlined" : false,
"rotation" : 0,
"scale" : 0,
"custom_css" : "",
"_id" : ObjectId("52ebf44571616b8716000010")
},
{
"type" : "image",
"file" : "",
"external_url" : "",
"size" : 40,
"pos_x" : 0,
"pos_y" : 0,
"rotation" : 0,
"scale" : 0,
"custom_css" : "",
"_id" : ObjectId("52ebf4d971616b8716000011")
}
],
"number" : 0,
"pos_x" : 0,
"pos_y" : 0,
"presentation_id" : 46,
"rotation_x" : 0,
"rotation_y" : 0,
"rotation_z" : 0,
"scale" : 1
}
我需要删除一个子文档,在这种情况下,“组件”的 _id 等于“52ebf4d971616b8716000011”。
我已经试过了:
db.slides.update({"components._id": ObjectId("52ebf4d971616b8716000011")},
{$pull: {"components._id": ObjectId("52ebf4d971616b8716000011"}})
但它不起作用,文档保持不变。
【问题讨论】:
-
算了。我问自己。问题出在 $pull 结构中: db.slides.update({"components._id": ObjectId("52ebf4d971616b8716000011")}, {$pull: {"components": { "_id": ObjectId("52ebf4d971616b8716000011") }}})
-
你能发布你最终做了什么来解决它吗?
标签: mongodb document subdocument