How to update a mongoDB collection having around 5 million documents in the collection? Which is the fastest way to update these documents?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
On using
updateMulti()
, it will update all the matching documents in one transaction. It is more efficient than updating the files one by one, as it decreases the network round-trips across the DB and the application .For updating a large number of documents (5 million), I suggest you making use of
bulk operations
rather thanupdateMulti()
. It allows you to do many write operations in groups; lowering the extra work of individual update instructions.