vendredi 3 avril 2015

Need help qureying MongoDB with nodeJS. Getting undefined is not a function on the following code

The following code is giving me undefined is not a function. My database has 22 numbers in it and I want to get the average. What am I doing wrong?



router.get('/mean', function(req, res) {
var db = req.db;
var collection = db.get('numbercollection');
collection.aggregate([
{$group : {_id : null,
mean : {$avg : "$number"}
}
}], function(err, result) {
console.log(result);
});
});


Just let me know if you need more information. Thanks.


Aucun commentaire:

Enregistrer un commentaire