mongodb - 使用 MongoDB Aggregation 将两个列表合并为一个对象
问题描述
我正在使用 mongoDB,并且我有类似于以下内容的文档
{
"files": ["Customers", "Items", "Contacts"],
"counts": [1354, 892, 1542],
...
}
并使用聚合管道阶段,我想将上述内容转换为更像..
{
"file_info": [
{"file_name": "Customers", "record_counts": 1354},
{"file_name": "Items", "record_counts": 892},
{"file_name": "Contacts", "record_counts": 1542}
]
}
我试过使用$map, $reduce, and $arrayToObject
但没有任何成功。我可以使用哪些运算符从我当前所在的位置到达我需要的位置?
解决方案
推荐阅读
- c# - EF 核心中的 DbGeography 等价物是什么?
- python - ValueError:拟合逻辑回归模型时输入形状错误
- encoding - 为什么像素的权重不一样?
- php - PHP preg_replace 逗号选择选项
- postgresql - 如何在 Hasura 中建模涉及多个字段的自定义关系?
- javascript - React/React Native:子组件状态的变化会重新渲染整个组件
- javascript - 如何在发布请求中上传带有 csrf 令牌的文件
- c# - app.ApplicationServices.GetService() 有什么作用?
- c# - Discord.NET 对象引用未设置为对象的实例
- entity-framework-6 - 在 EF6 中动态创建 DbConfiguration