i cannot use $match alone as it won’t uitlise the index mappings defined in atlas.
You could create an index on the expiryDate
field for the example on this post. You can then do the same for your array and string type fields.
The documents can then be found using $match
alone. E.g. (from previous reply of mine):
db.collection.aggregate({
'$match': {
'$or': [
{ expiryDate: { '$exists': false } },
{ expiryDate: null },
{ expiryDate: { '$gte': ISODate("2022-01-01T00:00:00.000Z") } } /// <--- Assuming this is the current date for example purposes. Modify as required.
]
}
})
Have you compared the performance of a standard index and $match
alone versus the Atlas search index w/ $search
alone to see if it suits your use case? I’ve not yet tested this myself but if your concern is utilisation of indexes then you can create the index mentioned and run an db.collection.explain(“executionStats”) to see the results where there should be some level of index usage.
Regards,
Jason