1

我有一个包含以下键数组对的文档:

"home" : [
        "Kevin Garnett",
        "Paul Pierce",
        "Rajon Rondo",
        "Brandon Bass",
        " 5 sec inbound",
        "Kevin Seraphin"
    ]

我想" 5 sec inbound"从数组中删除元素并使用以下命令(在 MongoDB shell 中):

>coll.update({},{"$pull":{"home":" 5 sec inbound"}})

正如查询所验证的那样,这不起作用:

>coll.findOne({"home":/5 sec inbound/})
"home" : [
        "Kevin Garnett",
        "Paul Pierce",
        "Rajon Rondo",
        "Brandon Bass",
        " 5 sec inbound",
        "Kevin Seraphin"
    ]

任何帮助将不胜感激!

4

1 回答 1

1

同样的陈述对我有用:

> db.test.insert({"home" : [
...         "Kevin Garnett",
...         "Paul Pierce",
...         "Rajon Rondo",
...         "Brandon Bass",
...         " 5 sec inbound",
...         "Kevin Seraphin"
...     ]})
> db.test.find({"home":/5 sec inbound/}).count()
1
> db.test.update({},{"$pull":{"home":" 5 sec inbound"}})
> db.test.find({"home":/5 sec inbound/}).count()
0
于 2012-11-14T18:32:22.570 回答