1
我想获得每个地区的学生数量。 我有一个模式,看起来像mapReduce使用node.js和猫鼬
var mongoose = require('mongoose');
var schema = mongoose.Schema;
var studentSchema = new mongoose.Schema(
{
"name":String,
"address" :{
"locality":String
}
});
module.exports = mongoose.model('Student', studentSchema);
我那么有一些Node.js的代码
var Student = require('../../../models/Student');
module.exports.getStudentsBasedOnLocality = function(){
var o = {};
o.map = function() {
emit(Student.address.locality, 1)
}
o.reduce = function (k, vals) {
return vals.length
}
Student.collection.mapReduce(o, function (err, results) {
if(err) throw err;
console.log(results)
})
};
的错误我得到的是。有关我可能做错什么的提示?
类型错误:
Cannot read property 'out' of undefined
at Collection.mapReduce (C:\***\node_modules\mongodb\lib\collection.js:2961:21)
at NativeCollection.(anonymous function) [as mapReduce] (C:\***\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:136:28)