4 ms·
The example would be much clearer as an aggregation query. Roughly: db.demo.aggregate([ { $match: { score: { $gt: 0 }, person:
by redler 14y ago
The example would be much clearer as an aggregation query. Roughly:
db.demo.aggregate([
{ $match: { score: { $gt: 0 },
person: { $in: ["bob","jake"] }}},
{ $group: { _id: "person",
sumscore: { $sum: "$score" },
avgscore: { $avg: "$score" },
minscore: { $min: "$score" },
maxscore: { $max: "$score" },
count: { $sum: 1 }}}
]);