mongo-doc

作者: 泠泉 | 来源:发表于2019-06-19 15:36 被阅读0次

    如何将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'}},
    

    相关文章

      网友评论

          本文标题:mongo-doc

          本文链接:https://www.haomeiwen.com/subject/ldekqctx.html