我是 MongoDB 的新手。我有一个典型的用例。这是我的单文档 JSON 结构。
{
"category":"cat_1",
"_id": "id1",
"levels":[
{
"id":"l1",
"orders":[
{
"id":"o1",
"screens":[
{
"id":"l1o1s1",
"name":"screen1"
},
{
"id": "l1o1s2",
"name": "screen2"
}
]
},
{
"id": "o2",
"screens": [
{
"id": "l1o2s1",
"name": "screen3"
},
{
"id": "l1o2s2",
"name": "screen4"
}
]
}
]
},
{
"id": "l2",
"orders": [
{
"id": "o1",
"screens": [
{
"id": "l2o1s1",
"name": "screen5"
},
{
"id": "l2o1s2",
"name": "screen6"
}
]
},
{
"id": "o2",
"screens": [
{
"id": "l2o2s1",
"name": "screen7"
},
{
"id": "l2o2s2",
"name": "screen8"
}
]
}
]
}
]
}
在这里,我想获取仅给定屏幕 ID 的数据。例如,如果["l1o1s1","l1o2s2","l2o1s1","l2o2s1"]
我的屏幕 ID 列表应该在文档中找到,那么我想要如下结果(它应该返回仅在输入中给出的屏幕 ID)
{
"category":"cat_1",
"_id": "id1",
"levels":[
{
"id":"l1",
"orders":[
{
"id":"o1",
"screens":[
{
"id":"l1o1s1",
"name":"screen1"
}
]
},
{
"id": "o2",
"screens": [
{
"id": "l1o2s2",
"name": "screen4"
}
]
}
]
},
{
"id": "l2",
"orders": [
{
"id": "o1",
"screens": [
{
"id": "l2o1s1",
"name": "screen5"
},
]
},
{
"id": "o2",
"screens": [
{
"id": "l2o2s1",
"name": "screen7"
}
]
}
]
}
]
}
屏幕的输入不必仅在单个文档中。它也可能存在于其他类别中。那么它应该只返回带有提到的屏幕 ID 的文档。
有什么办法可以像这样检索数据吗?