Select * group by in mongo aggregation

后端 未结 4 1434
名媛妹妹
名媛妹妹 2021-02-08 02:25

I am trying to do something that I think is quite simple. Suppose I have a series of records in mongo that have a common key, and variable number of attributes. I want to select

4条回答
  •  星月不相逢
    2021-02-08 02:53

    use $addToSet to the group,it will work

    db.data.aggregate(
        { $group : {
                _id : "$Name",
                x: { $addToSet: "$x" },
                y: { $addToSet: "$y" },
                z: { $addToSet: "$z" },
        }}
    )
    

提交回复
热议问题