我想像下面这样查询,但这里只包含一个$cond
。
如何使用两个$cond
进行查询
collection.aggregate(
{
$match : {
'_id' : {$in:ids}
}
},
{
$group: {
_id: '$someField',
...
count: {$sum: { $cond: [ { $eq: [ "$otherField", false] } , 1, 0 ] }}
}
},
function(err, result){
...
}
);
发布于 2013-12-31 04:46:42
您希望在{$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
operator文档:http://docs.mongodb.org/manual/reference/operator/aggregation/#boolean-operators
https://stackoverflow.com/questions/20836978
复制相似问题