合并MongoDB的两个字段
我使用了放松的聚合,但我有一个错误 我需要输出。其余数据也以相同的格式使用
[
{
"_id": "767",
"customId": [
"growth",
"fine"
],
"length": [
1526,
95
]
},
{
"_id": "66",
"customId": [
"height",
"good"
],
"length": [
86,
68
]
}
]
,我使用了放松聚合,但我有一个错误 我需要输出。其余的数据也以相同的格式
[
{
"_id": "767",
"merged": [
{
"customId": "growth",
"length": 1526
},
{
"customId": "fine",
"length": 95
}
]
},
{
"_id": "66",
"merged": [
{
"customId": "height",
"length": 86
},
{
"customId": "good",
"length": 68
}
]
}
]
我使用Postman来知道它是否有效
I used unwind aggregation but I am with an error
I need output like. the remaining data is also in the same format
[
{
"_id": "767",
"customId": [
"growth",
"fine"
],
"length": [
1526,
95
]
},
{
"_id": "66",
"customId": [
"height",
"good"
],
"length": [
86,
68
]
}
]
I used unwind aggregation but I am with an error
I need output like. the remaining data is also in the same format
[
{
"_id": "767",
"merged": [
{
"customId": "growth",
"length": 1526
},
{
"customId": "fine",
"length": 95
}
]
},
{
"_id": "66",
"merged": [
{
"customId": "height",
"length": 86
},
{
"customId": "good",
"length": 68
}
]
}
]
I am using postman to know whether it is working or not
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
$ zip
从两个数组中构造对,并使用$ arrayElemat
来争吵您的预期输出。这是 mongo playground 供您参考。
You can use
$zip
to construct pairs from the 2 arrays and use$arrayElemAt
to wrangle to your expected output.Here is the Mongo Playground for your reference.