我有以下数据集:
{
zipcode: '01228000',
personalInfo: [ 'tag1', 'tag2' ],
skills: [ 'skill1', 'skill2' ]
},
{
zipcode: '01228001',
personalInfo: [ 'tag1', 'tag3' ],
skills: [ 'skill1', 'skill3' ]
}
我想用mongodb聚合框架生成以下输出。
{
"result" : [
{
"_id" : '01228000',
"zipcodeCount" : 1
},
{
"_id" : '01228001',
"zipcodeCount" : 1
},
{
"_id" : 'tag1',
"tagCount" : 2
},
{
"_id" : 'tag2',
"tagCount" : 1
},
{
"_id" : 'tag3',
"tagCount" : 1
},
{
"_id" : 'skill1',
"skillCount" : 2
},
{
"_id" : 'skill2',
"skillCount" : 1
},
{
"_id" : 'skill3',
"skillCount" : 1
}
],
"ok" : 1
}
我知道$ project,$ unwind和$ group aggregate命令。但是我无法理解如何将它们放在一起以生成至少类似的结果集。