SELECT *
FROM article
WHERE id >= 15
AND id NOT IN (27,99,101,110)
Hi,
Depending on your use case and application, one solution is to segment off the data - a similar approach to the hybrid schema design. You could try to use either time or application pagination to segment and reduce the searchable dataset. For example, search only articles from the past 3 days to reduce the amount of data to be filtered.
Worth noting that $nin is not very selective since it often matches a large portion of the index. As a result, a $nin
query with an index may perform no better than a $nin
query that must scan all documents in a collection.
If possible, it is preferable to change the document structure such that queries can be performed on values that exist, instead of documents that don’t contain specific values. In addition, you can add other selective filters (i.e. date/timestamp) to increase the selectivity of $nin
.
You may also find Socialite: Feed Service a useful resource.
Regards,
Wan.