So I'm kinda new to node.js. And I can't understand why Aggregate queries don't work for me. I've tried the same query at the Mongo Shell and it worked perfectly. Here's the code:
db.collection("companies").aggregate({$match:
{$or:
[{ $and:
[{ left: {$gt: 2}}, {left: {$lt: 11}}]},
{ $and:
[{ right: {$gt: 2}}, {right: {$lt: 11}}]}]}},
{ $group:
{_id:null,
Sum:{$sum: "$earn"}}},
function(err, data){
if (err) throw err;
console.log(data[0]);
console.log(data.value);
console.log(data.Sum);
});
Console output:
undefined
undefined
undefined