we have 3M records in collection. we want to populate array fields called “array1” and “array2” if doesn’t exist in document.
what would be the best way to make search faster for documents which don’t have array fields “array1” and “array2”. We can use “$exist” but it’s taking longer time
My gut feeling is that creating such an index would as slow as just doing the query for the update. I think that it could even be slower as the index has to be written to disk and then updated when the arrays are populated.
It may however distribute the work over a longer period and reduce the CPU spike.
But as with any performance issues, gut feeling is not always right.