Parameters
[options.ordered «Boolean» = true] if true, will fail fast on the first error encountered. If false, will insert all the documents it can and report errors later. An with
ordered = false
is called an “unordered”insertMany()
.[options.rawResult «Boolean» = false] if false, the returned promise resolves to the documents that passed mongoose document validation. If
true
, will return the with amongoose
property that contains if this is an unorderedinsertMany
.[options.limit «Number» = null] this limits the number of documents being processed (validation/casting) by mongoose in parallel, this does NOT send the documents in batches to MongoDB. Use this option if you’re processing a large number of documents and your app is running out of memory.
[options.populate «String|Object|Array» = null] populates the result documents. This option is a no-op if
rawResult
is set.
Returns:
Shortcut for validating an array of documents and inserting them into MongoDB if they’re all valid. This function is faster than .create()
because it only sends one operation to the server, rather than one for each document.
Mongoose always validates each document before sending insertMany
to MongoDB. So if one document has a validation error, no documents will be saved, unless you set .
This function triggers the following middleware.
insertMany()