Hi everyone,
In order to clean once per day one of my collection with a two-field query, I wanted to create a Scheduled Trigger on Atlas. I just need to run a “deleteMany” operation on 2 fields. This collection is pretty big, as there are more than 175 million documents, so I created a specific index for the query I need to run.
For a mysterious reason, if I run my operation ({ fieldA: { "$eq": null }, fieldB: { "$lt": someDate } }
), the selected index is not the one I created. Rather than selecting the compound index I created ({ fieldA: 1, fieldB: 1}
), MongoDB selects the prefix ({ fieldA: 1 }
). every time. My query runs a first IXSCAN with the “fieldA” index, and then runs a COLLSCAN inside that subset of documents. However, a subset of more than 80 millions documents is still huge, so the query runs for an eternity.
The “hint” method resolves this issue, but I cannot make it work inside a Trigger Function. In the MongoDB API documentation of the “deleteMany” operation, hint does not appear, which is really blocking me right now.
Am I missing something ? Is there no way to run a “deleteMany” operation with “hint” option inside a Trigger Function ?
Thanks in advance !
PS : the Atlas Cluster I am targeting runs MongoDB v4.4, and no, I cannot make a TTL Index to cover my use case.