假设我有以下结构:
{
"rootDocument": {
"key1": {
"objA": {
"myId": "1",
"field1": {
...,
"objA": {
"myId": "2",
"field1": {
...,
"objA": {
... // any number of nested levels
}
}
}
}
}
},
"key2": {
"objA": {
"myId": "1",
"field1": {
...,
"objA": {
"myId": "2",
"field1": {
...,
"objA": {
... // any number of nested levels
}
}
}
}
}
},
...
"keyM": {
...
}
}
}
我希望能够通过 objA
字段找到给定的 n
(可能是 myId
级深)。我查看了 $graphLookup
,但它从根文档开始递归搜索,我认为它并没有完全按照我的意思去做。
rootDocument
本质上充当具有键 key1...keyM
的映射。
注意:我们并没有真正控制 JSON 结构,因为我们正在尝试将遗留应用程序移至 Mongodb,我只是想证明我们需要支持的查询将起作用。