如何将List打平,放到set中
db.collection.aggregate([
{$group:{
_id: null,
selectedTags: { $push: '$tags' }
}},
{$project: {
selectedTags: { $reduce: {
input: "$selectedTags",
initialValue: [],
in: {$setUnion : ["$$value", "$$this"]}
}}
}}
])
[$addFields: [userIds: [$reduce: [input: '$userIdLists', initialValue: [], in: [$setUnion: ['$$value', '$$this']]]]]],
join on orgId
{$addFields:{'totalUser':[{orgId:885, num:100},{orgId:966,num:101}]}},
{$addFields:{'totalUser': {$filter:{input:'$totalUser',as:'item',cond:{$eq:['$$item.orgId','$orgId']}}}}},
{$addFields:{'totalUser': {$arrayElemAt:['$totalUser',0]}}},
{$addFields:{'totalUser': '$totalUser.num'}},