小编G.M*_*ika的帖子

分组文档时组合数组

数据库中的文件格式如下

{
  product: 'product1',
  state: 'state1',
  nondnd: [1, 2, 3],
  dnd: [4, 5],
  land: [],
  emails: ['a', 'b', 'c']
},
{
  product: 'product1',
  state: 'state1',
  nondnd: [9, 8, 2],
  dnd: [10, 7, 11],
  land: [2, 4, 6, 8],
  emails: ['d']
},
{
  product: 'product1',
  state: 'state2',
  nondnd: [9, 8, 2],
  dnd: [10, 7, 11],
  land: [1, 3],
  emails: ['e', 'g']
}
Run Code Online (Sandbox Code Playgroud)

我需要根据产品和状态对上述文件进行分组,并按以下格式获取它们

{
  _id: {
    product: 'product1',
    state: 'state1'
  },
  nondnd: [1, 2, 3, 9, 8, 2],
  dnd: [4, 5, …
Run Code Online (Sandbox Code Playgroud)

mongodb mongodb-query aggregation-framework

9
推荐指数
1
解决办法
6427
查看次数