Filter out results that have a value for a field

Hello, I have a collection where documents can be marked as deleted by having the _deletedOn field set to the date/time that they were deleted. Documents that aren’t deleted either don’t have this field or the value for it is null. I’ve read through the documentation but there doesn’t seem to be anything for specifically omitting results for which a path exists or is non-null.

I’m trying to avoid introducing a separate $match stage for search results but it seems that I’ll have to either do that or filter the results after the query returns. Is there a way to do this within the $search pipeline stage?

Have you look at


and

Thank you for your reply, I have looked at those operators and they come close to solving the issue, the problem is that the field can be present in which case I need to be able to check for a null value which is not possible as far as I know.

For now I am just filtering it outside of the $search stage which isn’t ideal but at least it works.

Perhaps the following is better: