New in version 2.6.
insertcommand inserts one or more documents and returns a document containing the status of all inserts. The insert methods provided by the MongoDB drivers use this command internally.
The command has the following syntax:
insertcommand takes the following fields:
Field Type Description
string The name of the target collection.
array An array of one or more documents to insert into the named collection.
boolean Optional. If
true, then when an insert of a document fails, return without inserting any remaining documents listed in the
false, then when an insert of a document fails, continue to insert the remaining documents. Defaults to
document Optional. A document that expresses the write concern of the
insertcommand. Omit to use the default write concern.
insertto bypass document validation during the operation. This lets you insert documents that do not meet the validation requirements.
New in version 3.2.
Returns: A document that contains the status of the operation. See Output for details.
The total size of all the
documents array elements must be less than or equal to the
maximum BSON document size.
The total number of documents in the
documents array must be less than or equal to the
maximum bulk size.
Insert a document into the
The returned document shows that the command successfully inserted a document. See Output for details.
Insert three documents into the
The returned document shows that the command successfully inserted the three documents. See Output for details.
The returned document contains a subset of the following fields:
An array of documents that contains information regarding any error encountered during the insert operation. The
writeErrorsarray contains an error document for each insert that errors.
Each error document contains the following fields:
An integer that identifies the document in the
documentsarray, which uses a zero-based index.
Document that describe error related to write concern and contains the field:
The following is an example document returned for a successful
insert of a single document:
The following is an example document returned for an
insert of two documents that successfully inserted one document but encountered an error with the other document: