你好,我有一个在Robomongo中执行并按预期工作的查询:
db.av.group(
{
key: { roomId: 1},
cond: { dateOfDay: { $gte: new Date('12/01/2014'), $lt: new Date('12/30/2014') } },
reduce: function( curr, result ) {
result.total += curr.price;
result.count++;
},
initial: { total : 0,
count : 0
},
finalize: function(result) {
result.avg = Math.round(result.total / result.count);
}
}
)
在 express 应用程序中实现后:
app.get('/api/checkAv/:checkIn/:checkOut', function(req, res) {
var checkIn = req.params.checkIn,
checkOut = req.params.checkOut,
roomType = req.params.roomType;
model.Av.group(
{
key: { roomId: 1},
cond: { dateOfDay: { $gte: new Date('12/01/2014'), $lt: new Date('12/30/2014') } },
reduce: function( curr, result ) {
result.total += curr.price;
result.count++;
},
initial: { total : 0,
count : 0
},
finalize: function(result) {
result.avg = Math.round(result.total / result.count);
}
}
).exec(function(err, av) {
if (err)
res.send(err);
res.json(av);
});
});
我在控制台看到以下错误信息:
TypeError: Object function model(doc, fields, skipId) { if (!(this instanceof model)) return new model(doc, fields, skipId); Model.call(this, doc, fields, skipId); } has no method 'group' at /home/www/domain.com/api/routes/routes.js:58:18 at Layer.handle [as handle_request] (/home/www/domain.com/node_modules/express/lib/router/layer.js:82:5)
at next (/home/www/domain.com/node_modules/express/lib/router/route.js:100:13) at Route.dispatch (/home/www/domain.com/node_modules/express/lib/router/route.js:81:3)
at Layer.handle [as handle_request] (/home/www/domain.com/node_modules/express/lib/router/layer.js:82:5)
at /home/www/brasovapartments.com/node_modules/express/lib/router/index.js:234:24 at param (/home/www/domain.com/node_modules/express/lib/router/index.js:331:14) at param (/home/www/domain.com/node_modules/express/lib/router/index.js:347:14) at param (/home/www/domain.com/node_modules/express/lib/router/index.js:347:14) at Function.proto.process_params (/home/www/domain.com/node_modules/express/lib/router/index.js:391:3)
经过阅读,我发现有些人定义了一个名为“group”的属性,但不确定是在哪里和如何定义。这个问题是否与Mongoose模式有关?请给我一些提示。
group
命令被弃用后。 - JohnnyHK