I have a collection in mongodb named March2015, and in there my documents are with the following structure:
{ "user": <user>, "date": <date>, "times": <int> }
I then want to aggregate total times in that collection for a particular user. In mongo shell, I can do the following, for user 'eran':
db.March2015.aggregate([{$match: {user: "eran"}}, { $group: {_id: "$user", total: {$sum: "$times"}}}])
and I get the appropriate result. but then in my express.js server Im trying to get that data, I do the following:
var dbCollection = db.get('March2015');
dbCollection.aggregate([
{ $match: {
user: "eran"
}},
{ $group: {
_id: "$user",
total: { $sum: "$times" }
}}
], function (err, result) {
console.log(result);
});
but then, when I access the url that invokes the method, nothing happens and It says that undefined is not a function, on the line 'dbCollection.aggregate(..)`
Why the same function isnt working from my express.js server?