简体   繁体   中英

Is there a default batch size that is used by MongoDB in the Bulk API?

I am new to MongoDB and I have this question because I read in the following link : " How can I improve MongoDB bulk performance? " that MongoDB internally breaks the list down into 1000 operations at a time. However, I could not find this information in the MongoDB documentation.

Does this mean that when I insert 50,000 documents in a MongoDB collection using the Bulk API, MongoDB will internally break the list into batches of 1,000 and performing the bulk insert operation 50 times? If yes, would I achieve the same performance if I break down the list of 50,000 documents into sublists of 1,000 documents and using the bulk insert operation in a for loop? Which is the better approach?

Please help me understand.

Thanks.

Yes, if you insert 50,000 documents in a MongoDB collection using the Bulk API, mongo will break it down to 1000 operations at max. Ideally, you should make the batches of 1000 yourself and do the inserts but in this case it is not going to make any difference because data is already there in memory. You should not be accepting this huge amount of data in a single request in a production ready system. Client should be capable of sending small chunks of data so that you can store it in a queue on the server and process it in the background(some other thread).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM