mongodb $ pull与正则表达式匹配不起作用 [英] mongodb $pull matching with regexp not working

查看:77
本文介绍了mongodb $ pull与正则表达式匹配不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对列表进行更新,并愿意与regexp匹配. 条件/app/匹配.find但不匹配.update的事实表明我做错了. 还有其他方法可以得到类似的结果吗?

I am trying to perform an update on a list, willing to get a match with regexp. The fact that the criteria /app/ matches for .find but not for .update suggest i am doing something wrong. Is there any other way to get similar results?

> 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" ] }

推荐答案

以下是您要查找的代码:

Here's the code you're looking for:

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

基于从$pull 文档提取的信息

Based on info pulled from the $pull documentation.

我在此处添加了测试脚本.

这篇关于mongodb $ pull与正则表达式匹配不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆