mongodb $ pull匹配regexp无法正常工作

时间:2011-06-09 18:41:04

标签: mongodb

我正在尝试在列表上执行更新,愿意与regexp匹配。 标准/ app /匹配.find而不是.update这一事实表明我做错了。 有没有其他方法可以获得类似的结果?

> db.things.find({items:/app/})
{ "_id" : 3, "items" : [ "appstore.com", "engineapp.com", "asp.ca" ] }
> db.things.update({}, { $pull: { items: /app/} })
> db.things.find({items:/app/})
{ "_id" : 3, "items" : [ "appstore.com", "engineapp.com", "asp.ca" ] }

2 个答案:

答案 0 :(得分:10)

以下是您正在寻找的代码:

db.things.update({}, {$pull : { items: {$regex: 'app' } } })

基于从$pull documentation

中提取的信息

我添加了一个测试脚本here

答案 1 :(得分:0)

您只能$从数组中提取常量值,而不是匹配任何条件的值。

相关问题