arrays - mongodb: query to check if item in an array contains a particular string
问题描述
I have a collection called products
with the following items
[
{
name: 'Product 1'
images: ['http://staging.example.com/1', 'http://production.example.com/2'],
...
},
{
name: 'Product 2'
images: ['http://production.example.com/3'],
...
}
]
I want to find documents that contain string staging
in the images
array.
I tried couple of things like using $contains but mongo throws error saying I cannot use $contains with array.
解决方案
我认为您可能需要在这里进行正则表达式搜索。
尝试:
db.collection.find({images: /staging/});
推荐阅读
- ionic-framework - Ionic Vue - 主细节视图
- javascript - 如何计算由纬度和经度和海拔高度指定的两点(垂直)之间的距离?
- python - Django 无法呈现模板 url?
- python - python加载excel文件
- ms-word - Mendeley 和 Citavi 忽略以前的引用并将它们作为普通文本处理并从一个重新开始
- javascript - 为什么下面的代码随机突出显示名称?
- java - 在模块中发现重复的类(不包括包)
- ssl - 如何在 erlang/elixir 服务器上正确设置 SSL?
- python - Numpy 对 ND 数组进行布尔过滤很慢?
- angular - Angular 10 中的重复 ApiModule