I have the following query that I need to find the reverse.
db.contracts.aggregate([
{ $match: { currentBalance: { $gt: 0 }, status: 'open' } },
{ $project: { customer_id: 1, lastTransactionDate: 1, currentBalance: 1, status: 1 } }
])
I an trying not to use
$or: [ currentBalance: { $ne: 0 }, status: { $ne: 'open' } ]
What I would really like is to use $not: [ condition ]
as I will have more difficult aggregations to write. However I cannot find the right syntax. Any help appreciated. I am using mongodb 3.0.7
I think this is essentially what you mean (apologies if $not)
db.contracts.aggregate([
{
$match: {
currentBalance: { $not: { $gt: 0 } },
status: { $not: { $eq: 'open' } },
},
},
{
$project: {
customer_id: 1,
lastTransactionDate: 1,
currentBalance: 1,
status: 1
}
}
])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With