How to avoid error when updating an entire collection in loop?

I’m getting error when updating using a loop, a collection populated with 500 records. I tried to use a setTimeout after each update, but it looks like the update take place regardless the setTimeout. Is there a way to delay the update to make sure all updates are taking place?

Try to see if you can use bulkUpdate() to update everything at once.

Thanks a lot.
B ulkRemove works perfectly and very fast. Now, I will try the BulkInsert if it exists or BulkSave. I hope it will work as well, although it’s less critical for my application.