0

When using the $vectorSearch aggregation stage and specifying filter, using the $exists operator isn't supported, but another way of effectively doing the same thing is to check if the property value is null. For example:

{ property: null }

{ property: { $eq: null } }

This works fine when doing a $match aggregation stage; it successfully retrieves the documents that don't have property set to a value, or documents that have property set to null.

However, specifying this as filter when doing $vectorSearch doesn't work the same. It does not match to documents that don't have property .

Is there a way to $vectorSearch and filter by a property value that does not exist?

If not, you'd have to set the property values to null or some other value, and then query based on this value, rather than checking if the property exists or not. This would also mean having to update any existing $match queries that use $exists on the property.

You could also add a $match stage after the $vectorSearch stage but this isn't a great option when you want to limit the number of documents returned by $vectorSearch (because it could be limiting/excluding documents that would otherwise match).

Thanks!

2
  • Depending on the language you are using, you could try something like filter: { property: { $and [ { $ne: null }, { $ne: undefined } ] } } or { $nin: [null, undefined ] }. If you want to search on those fields not existing then reverse the comparisons above Commented Nov 7 at 11:31
  • It would be using the MongoDB Query Language, and unfortunately neither of these successfully filter by properties that don't exist when applied with $vectorSearch. And as a side note for future readers, filter: { property: { $and [ { $ne: null }, { $ne: undefined } ] } } isn't a correct filter. It'd be { $and: [{ property: { $ne: null } }, { property: { $ne: undefined }}] } Commented Nov 11 at 16:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.