我想像下面这样查询,但这只包含一个$cond
.
如何查询两个$cond
?
collection.aggregate(
{
$match : {
'_id' : {$in:ids}
}
},
{
$group: {
_id: '$someField',
...
count: {$sum: { $cond: [ { $eq: [ "$otherField", false] } , 1, 0 ] }}
}
},
function(err, result){
...
}
);
你想在里面使用复合表达式{$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){
...
}
);
The $and操作员 http://docs.mongodb.org/manual/reference/operator/aggregation/and/#exp._S_and记录在这里:http://docs.mongodb.org/manual/reference/operator/aggregation/#boolean-operators http://docs.mongodb.org/manual/reference/operator/aggregation/#boolean-operators
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)