简体   繁体   English

MongoDB中的$ pull操作不适用于我

[英]$pull operation in MongoDB not working for me

I have a document with the following key-array pair: 我有一个包含以下键数组对的文档:

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

I want to remove the element " 5 sec inbound" from the array and use the following command (in the MongoDB shell): 我想从数组中删除元素" 5 sec inbound" ,并使用以下命令(在MongoDB shell中):

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

This is not working as verified by a query: 不能通过查询验证:

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

Any help would be greatly appreciated! 任何帮助将不胜感激!

That very same statement works for me: 那句话对我有用:

> 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM