partialFilterExpression alternative to $in

partialFilterExpression

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: https://jira.mongodb.org/browse/SERVER-59508

Asya

2 Likes