MongoDB Bulk Write Operations
Posted By : Mohit Jain | 28-Oct-2018
Here are the things we require to perform bulk operations:-
1.) Bulk():- This is a bulk operation builder which is used to create list of write operations for a single collection.We have to initialize this builder in order to add the write operation list by using below points either by 2.) or 3.)
2.)db.collection.initializeOrderedBulkOp():- This is used to initialize Bulk() so that all write operations will execute sequentially.But this case has one limitation that if any of the error occurs while executing any operation in the list then remaining list operations will not execute further.
3.)db.collection.initializeUnorderedBulkOp():-This is used to initialize Bulk() so that all write operations will execute in unsequentially or in any order.The advantage of this over 2.) is that if any error occurs whiile executing any write operations then it will not effect remaining operations in the list.
4.)Bulk.execute():-This method is used to finally responsible to excute whole list of write operations.
First initialize lets say we have collection with name items
Then add write operations in the list
//add insert operations
//add update operations
//add replace operation