1

これは私の構造です:

{
    "_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"}})

しかし、それは機能しません。ドキュメントは同じままです。

4

2 に答える 2

2

components._id(配列である)からプルするのではなく、(配列ではない)からプルしようとしているため、試みられた更新は機能しませんcomponents_idドキュメントをプルしようとしているフィールドです) )。

クエリを次のように変更する必要があります。

db.slides.update(
  { 'components._id': some-id }, 
  { $pull: { components: { _id: some-id } } }); 

@ BryceAtNetwork23が提案したように。

于 2014-01-31T20:07:07.490 に答える
1

これを試して:

db.slides.update( {"components._id": ObjectId("52ebf4d971616b8716000011")},
{$pull: {components: {"_id": ObjectId("52ebf4d971616b8716000011")}}}, false, false)
于 2014-01-31T20:03:31.520 に答える