BulkWriteResult()A wrapper that contains the results of the
Bulk.execute()method.
Compatibility
This method is available in deployments hosted in the following environments:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
- MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
- MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Properties
BulkWriteResult has the following properties:
BulkWriteResult.acknowledgedBoolean indicating whether or not the bulk write was acknowledged.
BulkWriteResult.deletedCountCount of deleted documents.
BulkWriteResult.insertedCountCount of inserted documents.
BulkWriteResult.insertedIdsmongoshVersionDescription Example v1.x
Array of inserted documents by
ObjectId.[ ObjectId(...), ObjectId(...), ObjectId(...) ]v2.x
Map from each inserted document index to its
ObjectId.{ 0: ObjectId(...), 1: ObjectId(...), 2: ObjectId(...) }`
BulkWriteResult.matchedCountCount of matched documents.
BulkWriteResult.modifiedCountCount of modified documents.
BulkWriteResult.upsertedCountCount of upserted documents.
BulkWriteResult.upsertedIdsmongoshVersionDescription Example v1.x
Array of upserted documents by
ObjectId.[ ObjectId(...), ObjectId(...), ObjectId(...) ]v2.x
Map from each upserted document index to its
ObjectId.{ 0: ObjectId(...), 1: ObjectId(...), 2: ObjectId(...) }`
writeErrors Exception
If there is a write error while processing the bulk write, mongosh raises an exception that contains a writeErrors
property with the following fields:
writeErrorsAn array of documents that contains information regarding any error, unrelated to write concerns, encountered during the update operation.
writeErrorscontains an error document for each write operation that errors.Each error document contains the following fields:
writeErrors.indexInteger that identifies the write operation in the bulk operations list, which uses a zero-based index. See also
Bulk.getOperations().
writeErrors.codeInteger value identifying the error.
writeErrors.errmsgDescription of the error.
writeErrors.opA document identifying the operation that failed. For instance, an update or replace operation error will return a document specifying the query, the update, the
multi, and theupsertoptions. An insert opertation returns the document the operation tried to insert.
writeConcernError Exception
If there is a write concern error while processing the bulk write, mongosh raises an exception that contains a writeConcernError
property with the following fields:
writeConcernErrorDocument describing errors that relate to the write concern.
Changed in version 7.0.6: (also available in 6.0.14 and 5.0.30): When
BulkWriteResult()is received frommongos, write concern errors are always reported, even when one or more write errors occur. In previous releases, the occurrence of write errors could cause theBulkWriteResult()to not report write concern errors.The
writeConcernErrordocuments contains the following fields:writeConcernError.codeInteger value identifying the cause of the write concern error.
writeConcernError.errmsgDescription of the cause of the write concern error.
writeConcernError.errInfo.writeConcernThe write concern object used for the corresponding operation. For information on write concern object fields, see Write Concern Specification.
The write concern object may also contain the following field, indicating the source of the write concern:
writeConcernError.errInfo.writeConcern.provenanceA string value indicating where the write concern originated (known as write concern
provenance). The following table shows the possible values for this field and their significance:Provenance Description clientSuppliedThe write concern was specified in the application.
customDefaultThe write concern originated from a custom defined default value. See
setDefaultRWConcern.getLastErrorDefaultsThe write concern originated from the replica set's
settings.getLastErrorDefaultsfield.implicitDefaultThe write concern originated from the server in absence of all other write concern specifications.