對於下面的模式(僞代碼)。貓鼬組的結果按年份和月份
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