CNode

mongoose 按照日期归档

问答
Wwocaatm发布于9 年前最后回复9 年前6 回复4350 浏览0 收藏

有大神知道怎么通过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 } ]

这种聚合怎么写啊

查看回复

回复 (6)

J
JarvisQJ#1·9 年前

https://cnodejs.org/topic/599fd8f3f36051a45246c34e 参考这个吧,能解决一半

D
daileimail#3·9 年前

用 mapreduct

W
wocaatm#4·9 年前
引用 daileimail用 mapreduct

@daileimail 能说说具体怎么写么

N
nnliang#5·9 年前

做个冗余字段记录年月,直接用年月做聚合

W
wocaatm#6·9 年前
引用 nnliang做个冗余字段记录年月,直接用年月做聚合

@nnliang 能加个qq具体聊聊么?跪谢

参与回复
登录后即可参与回复。登录