我有一个mongoose模型
'use strict';
var mongoose = require('bluebird').promisifyAll(require('mongoose'));
var Schema = mongoose.Schema;
function toLower (v) {
return v.toLowerCase();
}
var Signup = new Schema({
name: { type: String, required: true },
email: { type: String, unique: true, required: true, set: toLower },
position: { type: String },
area: String,
companySize: Number,
created: { type: Date, default: Date.now }
});
module.exports = mongoose.model('Signup', Signup);
我想按创建分组(日期格式化为日期)并计算_ids的数量。
我是mongoose和bluebird的新手......有人能为我提供一个例子吗? THX !!!
答案 0 :(得分:0)
我设法得到了我想要的东西:
SignupModel
.aggregate([
{
$group: {
_id: { $week: "$created" },
"count": { "$sum": 1 }
}
}
])
.execAsync()
.then(responseWithResult(res))
.catch(handleError(res));
=>按创建的组(周)并将它们相加