有大神知道怎么通过mongoose的聚合来实现文章归档的功能么? { "_id" : ObjectId(“51b6e603e3efef161b000003”), “title”: “文章1”, “created” : ISODate(“2017-12-7T08:55:31.957Z”) } { "_id" : ObjectId(“51b6e603e3efef161b000003”), “title”: “文章2”, “created” : ISODate(“2017-12-6T08:55:31.957Z”) } { "_id" : ObjectId(“51b6e603e3efef161b000003”), “title”: “文章3”, “created” : ISODate(“2017-11-11T08:55:31.957Z”) }
怎么通过聚合来达到这种效果 [ { year: 2017, monthlyusage: [ { month: 12, article: [ { “_id”: xxxxx, title: “文章1” }, { “_id”: xxxxx, title: “文章2” } ] }, { month: 11, article: [ { “_id”: xxxxx, title: “文章3” } ] } ] }, { year: 2016, xxxxxx } ]
这种聚合怎么写啊
用 mapreduct
@daileimail 能说说具体怎么写么
做个冗余字段记录年月,直接用年月做聚合
@nnliang 能加个qq具体聊聊么?跪谢
@wocaatm 136625007