0 votes
1 view
in Web Technology by (43.2k points)

Mongoose 4.4 now has an insertMany function which lets you validate an array of documents and insert them if valid all with one operation, rather than one for each document:

var arr = [{ name: 'Star Wars' }, { name: 'The Empire Strikes Back' }];

Movies.insertMany(arr, function(error, docs) {});

If I have a very large array, should I batch these? Or is there no limit on the size of the array?

For example, I want to create a new document for every Movie, and I have 10,000 movies.

1 Answer

0 votes
by (92.8k points)

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

The sizes and grouping workings are internal performance details and are subject to change in future versions. Executing an ordered list of operations on a sharded collection will usually be slower than executing an unordered list since with an ordered list, each operation must wait for the previous operation to finish.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...