Mongodb select all fields group by one field and sort by another field

前端 未结 4 640
灰色年华
灰色年华 2021-02-09 03:44

We have collection \'message\' with following fields

_id |   messageId |  chainId | createOn

1   |       1     |    A     | 155
2   |       2     |    A     | 1         


        
4条回答
  •  太阳男子
    2021-02-09 04:12

    Replace this line:

    final DBObject group = new BasicDBObject("$group", groupFields);
    

    with this one:

    final DBObject group = new BasicDBObject("_id", groupFields);
    

提交回复
热议问题