我有一个包含products以下项目的集合
[
{
name: 'Product 1'
images: ['http://staging.example.com/1', 'http://production.example.com/2'],
...
},
{
name: 'Product 2'
images: ['http://production.example.com/3'],
...
}
]
Run Code Online (Sandbox Code Playgroud)
我想找到数组staging中包含字符串的文档images。
我尝试了一些方法,例如使用 $contains 但 mongo 抛出错误,说我不能将 $contains 与数组一起使用。
我认为您可能需要在这里进行正则表达式搜索。
尝试:
db.collection.find({images: /staging/});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5798 次 |
| 最近记录: |