partialFilterExpression alternative to $in

Hi all,

I have a collection with status field (Pending,Completed,Failed) & createdAt field.
I want to delete records that were created more than a month and status is not equal to “Completed”

Is there a way to do that?
It seem partialFilterExpression doesn’t support that



Partial filter expression is about indexes, when you want to index only a subset of your collection. You are asking about deleting records, that would be based on a query like {createdAt:{$lt:<some-date>}, status:{$ne:"Completed"}}

Are you maybe thinking about creating a partial TTL index to automatically do these deletions? You could create a partial index but it doesn’t support dynamic date expressions (more than a month) and you’re correct that it won’t allow negation in the partialFilterExpression. In the subject you mention $in - is that because for you status:{$in:["Pending", "Failed"]} is equivalent to {$ne:"Completed"}?

Good news is that partial indexes now support $in and $or - the docs haven’t been updated yet but you can see it here:



Great new, this is exactly the feature I needed. Thank you for your quick and detailed response

When 5.1 with [quote=“Asya_Kamsky, post:2, topic:180823”]
[/quote] will be released?

Does “Support $or, $in and multi-level expressions in partial indexes” feature is already implemented in mondogdb v6?

Yep, this is already out as part of version 6.0.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.