I'm trying to add a field to the existing collection in mongoDB (It has around 100k documents), when I'm using updateMany to add this, the request is updating a few records (around 2k) and facing TimeOut.
MongoServerError: Request timed out.
I've checked in the official MongoDB documentation and I can see there's an existing maxTimeMS function for the Cursor object but not for the updateMany. I tried to update using the cursor but it was very very slow.
db.myCollection.find({}).forEach(
//update logic here
)
What is the best way to handle this?