Convert ObjectID to String in mongo Aggregation

后端 未结 5 1189
我在风中等你
我在风中等你 2021-02-05 12:15

I\'m in this scenario right now: I have a collection X:

{
  _id:ObjectId(\'56edbb4d5f084a51131dd4c6\'),
  userRef:ObjectId(\'56edbb4d5f084a51131dd4c6\'),
  seria         


        
5条回答
  •  日久生厌
    2021-02-05 12:36

    You can simply use $toString to apply $concat in aggregation on ObjectIDs in the following way -

    $group: {
        '_id': {
            '$concat': [
                { '$toString' : '$userRef' },
                '-',
                { '$toString' : '$serialNumber'}
            ]
        },
    }
    

提交回复
热议问题