【发布时间】:2021-09-25 21:30:54
【问题描述】:
我的 mongo 集合名称测试,其中包含以下文档。
[
{
"title": "One",
"uid": "1",
"_metadata": {
"references": [
{
"uid": "2"
},
{
"asssetuid": 10
}
]
}
},
{
"title": "Two",
"uid": "2",
"_metadata": {
"references": [
{
"uid": "3"
},
{
"asssetuid": 11
}
]
}
},
{
"title": "Three",
"uid": "3",
"_metadata": {
"references": []
}
}
]
我想要以下格式的结果(对于 uid:1)
[
{
"title": "One",
"uid": 1,
"_metadata": {
"references": [
{
"asssetuid": 10
},
{
"asssetuid": 11
},
{
"title": "Two",
"uid": "2",
"_metadata": {
"references": [
{
"title": "Three",
"uid": "3"
}
]
}
}
]
}
}
]
对于 uid:2 我想要以下结果
[
{
"title": "Two",
"uid": 2,
"_metadata": {
"references": [
{
"asssetuid": 11
},
{
"title": "Three",
"uid": "3"
}
]
}
}
]
我在这里使用了哪个查询来获得受人尊敬的结果。根据它的uid。这里我想要父子关系中的结果。这是否可以使用 MongoDB 图形查找查询或我们可以用来获取结果的任何其他查询。请帮我解决这个问题。
新类型输出
[{
"title": "One",
"uid": 1,
"_metadata": {
"assets": [{
"asssetuid": 10,
"parent": 1
}, {
"asssetuid": 11,
"parent": 2
}],
"entries": [{
"title": "Two",
"uid": "2",
"parent": 1
}, {
"title": "Three",
"uid": "3",
"parent": 2
}]
}
}]
【问题讨论】:
-
好的...@SurajDalvi 所以你绝对想以嵌套形式解析引用,否则平面地图也可以?
标签: node.js mongodb mongodb-query