开发者

How to remove a reference in mongodb?

I have the following object

   {
        "_id" : ObjectId("4b8699aa3b97dc29dd000000"),
        "name" : "test",
        "email" : "test",
        "url" : "test",
        "items" : [
                {
                        "$ref" : "item",
                        "$id" : ObjectId("4b866a043b97dc22a9000001")
      开发者_如何学编程          }
        ]}

How can I remove the reference from items? I have the objectid for the reference? I tried the following, which does work for normal list items but not with a reference.

db.foo.update(foo, {$pull: {'items': {'$id': ObjectId("4b866a043b97dc22a9000001") } } })


The problem was the version. In the old version you have to give all the keys and values to pull. After updating to version 1.3.2 this was not necessary and the code worked.


try this:

db.foo.update(foo, {$pull: {'items': {'$id': new ObjectId("4b866a043b97dc22a9000001") } } })
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜