mongodb查询动态键
需要找到具有不同值和键的引用,应从1或2或3开始。请您提供帮助。
{
"quoteId": 1,
"screening": {
"101": 1,
"201": 1,
"301": 1,
"100": 1,
"200": 1,
"300": 1,
"111": 1,
"211": 1,
"311": 1
}
}
{
"quoteId": 2,
"screening": {
"101": 1,
"201": 1,
"301": 1,
"100": 1,
"200": 1,
"300": 1,
"111": 1,
"211": 2,
"311": 1
}
}
Need to find quoteIds where having different values and keys should start with 1 or 2 or 3. Could you please help.
{
"quoteId": 1,
"screening": {
"101": 1,
"201": 1,
"301": 1,
"100": 1,
"200": 1,
"300": 1,
"111": 1,
"211": 1,
"311": 1
}
}
{
"quoteId": 2,
"screening": {
"101": 1,
"201": 1,
"301": 1,
"100": 1,
"200": 1,
"300": 1,
"111": 1,
"211": 2,
"311": 1
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$ set
- 创建筛选数组字段,通过将对象(键值配对)转换为多个文档(通过$ $ objecttoArray
)和通过$ filter
的1或2或3的开始来实现正则$ match
-筛选
不是空数组的过滤文档。$ unset
- 删除筛选
字段。示例mongo playground
$set
- Createscreenings
array field, by converting object (key-value pair) to multiple documents (via$objectToArray
) and fulfill the regex with starting of 1 or 2 or 3 in$filter
.$match
- Filter documents thatscreenings
is not an empty array.$unset
- Removescreenings
field.Sample Mongo Playground