【发布时间】:2019-12-27 15:08:17
【问题描述】:
想要使用动态键从 Mongo DB 嵌套字段中搜索所有匹配模式。
数据库结构:
_id: 'dsdsdsadadad',
results: {
tables: {
jvm: {
data: [
{
Prediction: 1,
Jvm: 'service_name',
Status: 'OK'
},
{
second: 'New second set'
}
}
}
}
由$ 试用,
db.col_name.find('results.tables.jvm.data.$.Jvm': {'$regexp': 'service.*'})
通过使用$i
db.col_name.find('results.tables.jvm.data.$i.Jvm': {'$regexp': 'service.*'})
同时提供特定的密钥0,
db.col_name.find('results.tables.jvm.data.0.Jvm': {'$regexp': 'service.*'})
没有结果!
预期 O/P:
上面的文档以及所有 Jvm 以 service* 关键字开头的地方
谢谢,
【问题讨论】:
标签: regex mongodb nested mongodb-query