I am new in mongo world, and I would like to optimize my query cves = colCVE.find({cpe_searchField: {"$regex": cpe_regex}}).sort("Modified", -1)limit(limit).skip(skip).allow_disk_use(True) in order to avoid .skip since some blogs says when the data grows up then consume a lot of memory, and I would like to understand how to compute over _id and make quicker pagination over more than 300k objects. the below example is the search function that searches over a regex to match only the specific things instead of all rows.
def cvesForCPE(cpe, vulnProdSearch=False):
if not cpe:
return []
cpe_regex = cpe
final_cves = []
cpe_searchField = (
"vulnerable_product" if vulnProdSearch else "vulnerable_configuration"
)
# default strict search
cves = colCVE.find({cpe_searchField: {"$regex": cpe_regex}}).sort("Modified", -1).allow_disk_use(True)
final_cves = cves
final_cves = sanitize(final_cves)
return final_cves