对于下面的模式(伪代码)。猫鼬组的结果按年份和月份
var Post = {
title: "",
content: "",
date: new Date()
}
我想回到按月&年分组结果,所以像这样,再伪代码:与猫鼬今天上午由本月组
[
{ year: "2016",
month: "4",
results: [
{_id: "1232", title: "foo", content: "bar", date: "Some date" },
{_id: "1232", title: "foosdas", content: "barsdasda", date: "Some other date" } ] }
]
我一直在努力聚集和一年好,它不会返回实际的模型对象。
这是我目前的汇总查询
Post
.aggregate({
$group: {
_id : { year: { $year : "$date" }, month: { $month : "$date" }},
}
})
.exec(function (error, items) {
if (error) { return next(error); }
console.log(items);
res.append("x-count", count);
return res.json("Done");
});
你能忍受,你得和原来的文件呢? – BanksySan