How to group query with multiple $cond?
问题 I want to query like below, but this contains only one $cond . How to query with two $cond ? collection.aggregate( { $match : { '_id' : {$in:ids} } }, { $group: { _id: '$someField', ... count: {$sum: { $cond: [ { $eq: [ "$otherField", false] } , 1, 0 ] }} } }, function(err, result){ ... } ); 回答1: You want to use a compound expression inside {$cond:[]} - something like: collection.aggregate( { $match : { '_id' : {$in:ids} } }, { $group: { _id: '$someField', ... count: {$sum: { $cond: [ {$and :