我想查询如下,但这只包含一个$cond
.
如何用两个查询$cond
?
collection.aggregate( { $match : { '_id' : {$in:ids} } }, { $group: { _id: '$someField', ... count: {$sum: { $cond: [ { $eq: [ "$otherField", false] } , 1, 0 ] }} } }, function(err, result){ ... } );
Asya Kamsky.. 51
你想在里面使用复合表达式{$cond:[]}
- 比如:
collection.aggregate( { $match : { '_id' : {$in:ids} } }, { $group: { _id: '$someField', ... count: {$sum: { $cond: [ {$and : [ { $eq: [ "$otherField", false] }, { $eq: [ "$anotherField","value"] } ] }, 1, 0 ] }} } }, function(err, result){ ... } );
该$and
操作记录在这里:http://docs.mongodb.org/manual/reference/operator/aggregation/#boolean-operators
你想在里面使用复合表达式{$cond:[]}
- 比如:
collection.aggregate( { $match : { '_id' : {$in:ids} } }, { $group: { _id: '$someField', ... count: {$sum: { $cond: [ {$and : [ { $eq: [ "$otherField", false] }, { $eq: [ "$anotherField","value"] } ] }, 1, 0 ] }} } }, function(err, result){ ... } );
该$and
操作记录在这里:http://docs.mongodb.org/manual/reference/operator/aggregation/#boolean-operators