我可以在地图结果上使用arraytooBject mongodb吗
我有一个地图聚合管道,该管道映射值,但返回数组内部的数组。
"Codes": [
{
"$map": {
"input": "$$e.content",
"as": "e1",
"in": [
{
"thisCode": "$$e1.code",
"thisCodeDescription": "$$e1.codeDescroption"
}
]
}
}
]
结果,
"Codes": [
[
[
{
"thisCode": "132",
"thisCodeExplanation": "code stuff explanation"
}
]
]
]
我想使用多个K,V结果与仅一项尝试并尝试过。
"Codes": [
{
"$arrayToObject": {
"$map": {
"input": "$$e.content",
"as": "e1",
"in":
{
"k": "thisCode",
"v": "$$e1.code
}
}
}
}
]
看起来这样:
"Codes": [
{
"thisCode": "132
}
]
是否有一种方法可以通过在地图顶部的arraytooBject获取对象中的两个项目,从而导致两个项目而不是对象中有多个项目,而对k和v进行硬编码?
"Codes": [
{
"thisCode": "132",
"thisCodeExplanation": "code stuff explanation"
}
]
I have a map aggregate pipeline that maps the values but returns an array inside of an array.
"Codes": [
{
"$map": {
"input": "$e.content",
"as": "e1",
"in": [
{
"thisCode": "$e1.code",
"thisCodeDescription": "$e1.codeDescroption"
}
]
}
}
]
results to this
"Codes": [
[
[
{
"thisCode": "132",
"thisCodeExplanation": "code stuff explanation"
}
]
]
]
I would like to apply an arrayToObject to it with multiple k, v results versus just one and have tried.
"Codes": [
{
"$arrayToObject": {
"$map": {
"input": "$e.content",
"as": "e1",
"in":
{
"k": "thisCode",
"v": "$e1.code
}
}
}
}
]
to look like this:
"Codes": [
{
"thisCode": "132
}
]
is there a way to get both of the items in the object by arrayToObject on top of maps results to result in both items versus hard-coding the k and v if there are multiple items in the object?
"Codes": [
{
"thisCode": "132",
"thisCodeExplanation": "code stuff explanation"
}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要过分复杂,您不需要$ arraytoObject,只需要删除额外的括号:
Don't over complicate, you don't need $arrayToObject, you just need to remove extra brackets: