Hi all,
I'm trying to write a query that count the number of document that pass a condition using the aggregate function.
Is there any way to use $nin or something of its equivalent in the condition? Like:
db.collectionName.aggregate({
$group: {
_id: "$field1",
...,
count: {
$sum: {
$cond: [ { "$field2": {$nin: ["possibleValue1", "possibleValue2"]} }, 1, 0 ]
}
},
...
}
})
According to
http://docs.mongodb.org/manual/meta/aggregation-quick-reference/#comparison-expressions $nin is not one of the comparison expressions defined in aggregation framework.
If so is there anything that I can do to accomplish the same thing while still using aggregate?
I can't put the condition in $match because I might use the documents not passing the condition in other stages.
Thank you,
Nisrina.