我正在尝试在列表上执行更新,愿意与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" ] }
答案 0 :(得分:10)
以下是您正在寻找的代码:
db.things.update({}, {$pull : { items: {$regex: 'app' } } })
基于从$pull
documentation。
我添加了一个测试脚本here。
答案 1 :(得分:0)
您只能$从数组中提取常量值,而不是匹配任何条件的值。