Database Manual / Reference / mongosh Methods / Object Constructors

BulkWriteResult() (mongosh method方法)

BulkWriteResult()
A wrapper that contains the results of the Bulk.execute() method.包含Bulk.execute()方法结果的包装器。

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部署的完全托管服务
  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Properties属性

BulkWriteResult has the following properties:具有以下属性:

BulkWriteResult.acknowledged
Boolean indicating whether or not the bulk write was acknowledged.布尔值,指示批量写入是否被确认。
BulkWriteResult.deletedCount
Count of deleted documents.已删除文档的计数。
BulkWriteResult.insertedCount
Count of inserted documents.插入文档的计数。
BulkWriteResult.insertedIds
mongosh VersionDescription描述Example示例
v1.xArray of inserted documents by ObjectId.ObjectId插入的文档数组。[ ObjectId(...), ObjectId(...), ObjectId(...) ]
v2.xMap from each inserted document index to its ObjectId.从每个插入的文档索引映射到其ObjectId{ 0: ObjectId(...), 1: ObjectId(...), 2: ObjectId(...) }`
BulkWriteResult.matchedCount
Count of matched documents.匹配文档的计数。
BulkWriteResult.modifiedCount
Count of modified documents.已修改文档的计数。
BulkWriteResult.upsertedCount
Count of upserted documents.被打乱的文件数量。
BulkWriteResult.upsertedIds
mongosh VersionDescription描述Example示例
v1.xArray of upserted documents by ObjectId.ObjectId排列的已打乱顺序的文档数组。[ ObjectId(...), ObjectId(...), ObjectId(...) ]
v2.xMap from each upserted document index to its ObjectId.从每个被打乱的文档索引映射到其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:如果在处理批量写入时出现写入错误,mongosh会引发一个异常,该异常包含具有以下字段的writeErrors属性:

writeErrors

An array of documents that contains information regarding any error, unrelated to write concerns, encountered during the update operation. writeErrors contains an error document for each write operation that errors.一组文档,其中包含有关更新操作期间遇到的与写入关注无关的任何错误的信息。writeErrors包含每个出错的写入操作的错误文档。

Each error document contains the following fields:每个错误文档包含以下字段:

writeErrors.index
Integer that identifies the write operation in the bulk operations list, which uses a zero-based index. 用于标识批量操作列表中的写入操作的整数,该列表使用从零开始的索引。See also Bulk.getOperations().另请参阅Bulk.getOperations()
writeErrors.code
Integer value identifying the error.标识错误的整数值。
writeErrors.errmsg
Description of the error.错误描述。
writeErrors.op
A 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 the upsert options. An insert opertation returns the document the operation tried to insert.标识失败操作的文档。例如,更新或替换操作错误将返回一个文档,指定查询、更新、multiupsert选项。插入操作返回操作试图插入的文档。

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:如果在处理批量写入时出现写入关注错误,mongosh会引发一个异常,该异常包含具有以下字段的writeConcernError属性:

writeConcernError

Document describing errors that relate to the write concern.描述与写入关注相关的错误的文档。

Changed in version 7.0.6.在版本7.0.6中的更改。 (also available in 6.0.14 and 5.0.30也可在6.0.14和5.0.30中使用): When BulkWriteResult() is received from mongos, write concern errors are always reported, even when one or more write errors occur. :当从mongos收到BulkWriteResult()时,即使发生一个或多个写入错误,也总是会报告写入关注错误。In previous releases, the occurrence of write errors could cause the BulkWriteResult() to not report write concern errors.在以前的版本中,写入错误的发生可能会导致BulkWriteResult()不报告写入关注错误。

The writeConcernError documents contains the following fields:writeConcernError文档包含以下字段:

writeConcernError.code
Integer value identifying the cause of the write concern error.标识写入关注错误原因的整数值。
writeConcernError.errmsg
Description of the cause of the write concern error.写入关注错误原因的描述。
writeConcernError.errInfo.writeConcern

The 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.provenance

A 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.写入关注源于自定义的默认值。请参阅setDefaultRWConcern
getLastErrorDefaultsThe write concern originated from the replica set's settings.getLastErrorDefaults field.写入关注源于副本集的settings.getLastErrorDefaults字段。
implicitDefaultThe write concern originated from the server in absence of all other write concern specifications.在没有所有其他写入关注规范的情况下,写入关注源自服务器。