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.acknowledgedBoolean indicating whether or not the bulk write was acknowledged.布尔值,指示批量写入是否被确认。
BulkWriteResult.deletedCountCount of deleted documents.已删除文档的计数。
BulkWriteResult.insertedCountCount of inserted documents.插入文档的计数。
BulkWriteResult.insertedIds-
mongoshVersionDescription描述Example示例v1.x Array of inserted documents by按ObjectId.ObjectId插入的文档数组。[ ObjectId(...), ObjectId(...), ObjectId(...) ]v2.x Map from each inserted document index to its从每个插入的文档索引映射到其ObjectId.ObjectId。{ 0: ObjectId(...), 1: ObjectId(...), 2: ObjectId(...) }`
BulkWriteResult.matchedCountCount of matched documents.匹配文档的计数。
BulkWriteResult.modifiedCountCount of modified documents.已修改文档的计数。
BulkWriteResult.upsertedCountCount of upserted documents.被打乱的文件数量。
BulkWriteResult.upsertedIds-
mongoshVersionDescription描述Example示例v1.x Array of upserted documents by按ObjectId.ObjectId排列的已打乱顺序的文档数组。[ ObjectId(...), ObjectId(...), ObjectId(...) ]v2.x Map 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属性:
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.writeErrors包含每个出错的写入操作的错误文档。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().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.multi和upsert选项。插入操作返回操作试图插入的文档。
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属性:
writeConcernErrorDocument 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 frommongos, 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()不报告写入关注错误。ThewriteConcernErrordocuments contains the following fields:writeConcernError文档包含以下字段: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.setDefaultRWConcern。getLastErrorDefaultsThe write concern originated from the replica set's写入关注源于副本集的settings.getLastErrorDefaultsfield.settings.getLastErrorDefaults字段。implicitDefaultThe write concern originated from the server in absence of all other write concern specifications.在没有所有其他写入关注规范的情况下,写入关注源自服务器。