MongoDB insert many documents limit?

2,729 views
Skip to first unread message

sobr...@gmail.com

unread,
Sep 11, 2016, 3:14:38 PM9/11/16
to mongodb-user
I would like to start learning about indexes in MongoDB, thus I want to populate my collection with many documents ( about 1000000 ). I am creating array of objects first, then I want to run insertMany function, but nothing happens. Is any limit when inserting documents? How is the working method for doing this?

Nishant Bhardwaj

unread,
Sep 15, 2016, 7:32:21 AM9/15/16
to mongodb-user

Hi Sobriodev,

You can learn more about Indexes in the MongoDB manual.

As you stated:

I am creating array of objects first, then I want to run insertMany function, but nothing happens.

By ‘nothing happens’ do you mean no document was inserted ? Did you see any error messages ?

For insertMany function, each group of operations can have at most 1000 operations. If a group exceeds this limit, MongoDB will divide the group into smaller groups of 1000 or less. For example, if the queue consists of 2000 operations, MongoDB creates 2 groups, each with 1000 operations.

The sizes and grouping mechanics are internal performance details and are subject to change in future versions. You can further read about insertMany behaviours in the MongoDB manual.

One sample code that works in mongo shell with v3.2 server is below:

arr = [];

for (i =0; i < 1000000 ; i++) { 
            arr.push({ "x" : i }) ; 

            }

//set ordered to false to make inserts faster
db.bulk.insertMany(arr, { ordered: false})

If you have further questions, can you please provide the information below:

  • The version of MongoDB.
  • The driver language and version used.
  • Typical document size.
  • Sample code used to insert the documents.

Regards,

Nishant

greatghoul

unread,
Sep 15, 2016, 9:05:25 PM9/15/16
to mongod...@googlegroups.com
One sample code that works in mongo shell with v3.2 server is below:

The sample is super fast, thank you.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/56f856ce-15a0-48bd-a091-7537a1960d22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
 greatghoul - Ask and Learn!
Reply all
Reply to author
Forward
0 new messages