I have collection of objects where each object contains versions some of which have delete field and would like to filter these which were not deleted or later than the given timestamp.
db
.getCollection('test')
.aggregate([
{$project:
{versions:
{$filter:
{input: '$versions',
as: 'version',
cond:
{
$or: [
{$gte: ['$$version.delete', 3]},
{'$$version.delete': {$exists: false}}
]
}
}
}
}
}
])
but field name probably can't be used inside filter because I get an error: invalid operator '$$version.delete'
Any ideas what is the proper syntax of this query?
You want to use aggregation syntax for checking type of delete field and comparing it to missing
which is what $exists:false
would be:
{$eq:[{$type:'$$version.delete'},"missing"]}
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