Definition定义
WriteResult()A wrapper that contains the result status of一个包含mongoshwrite methods.mongosh写入方法结果状态的包装器。Note
db.collection.insert()and和db.collection.update()are deprecated.已弃用。The results returned by the replacement methods have a different format. For output similar to替换方法返回的结果具有不同的格式。对于类似于WriteResult(), consider usingdb.collection.bulkWrite().WriteResult()的输出,考虑使用db.collection.bulkWrite()。
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属性
The WriteResult() has the following properties:WriteResult()具有以下属性:
WriteResult.nInsertedThe number of documents inserted, excluding插入的文档数,不包括upserteddocuments. SeeWriteResult.nUpsertedfor the number of documents inserted through an upsert.upserted文档。有关通过追加插入插入的文档数,请参阅WriteResult.nUpserted。
WriteResult.nMatchedThe number of documents selected for update.选择要更新的文档数。If the update operation results in no change to the document, e.g.如果更新操作导致文档没有更改,例如$setexpression updates the value to the current value,nMatchedcan be greater thannModified.$set表达式将值更新为当前值,nMatched可以大于nModified。
WriteResult.nModifiedThe number of existing documents updated. If the update/replacement operation results in no change to the document, such as setting the value of the field to its current value,已更新的现有文档数量。如果更新/替换操作导致文档没有更改,例如将字段的值设置为当前值,则nModifiedcan be less thannMatched.nModified可以小于nMatched。
WriteResult.nUpsertedThe number of documents inserted by an upsert.upsert插入的文档数量。
WriteResult._idThe追加_idof the document inserted by anupsert. Returned only if anupsertresults in an insert.upsert的文档的_id。仅当upsert导致插入时才返回。
WriteResult.nRemovedThe number of documents removed.删除的文档数量。
WriteResult.writeErrorA document that contains information regarding any error, excluding write concern errors, encountered during the write operation.包含有关写入操作期间遇到的任何错误(不包括写入关注错误)的信息的文档。WriteResult.writeError.codeAn integer value identifying the error.标识错误的整数值。
WriteResult.writeError.errmsgA description of the error.错误的描述。
WriteResult.writeError.errInfoA document that contains information regarding any write errors, excluding write concern errors, that were encountered during the write operation.一种文档,其中包含有关写入操作过程中遇到的任何写入错误(不包括写入关注错误)的信息。When an operation fails schema validation, the server produces an error under this field explaining why the document did not match against the collection's validator expression.当操作未能通过架构验证时,服务器会在此字段下产生一个错误,解释文档与集合的验证器表达式不匹配的原因。
WriteResult.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:当从WriteResult()is received frommongos, write concern errors are always reported, even when one or more write errors occur.mongos收到WriteResult()时,即使发生一个或多个写入错误,也总是会报告写入关注错误。In previous releases, the occurrence of write errors could cause the在以前的版本中,写入错误的发生可能会导致WriteResult()to not report write concern errors.WriteResult()不报告写入关注错误。WriteResult.writeConcernError.codeAn integer value identifying the cause of the write concern error.一个整数值,用于标识写入关注错误的原因。
WriteResult.writeConcernError.errmsgA description of the cause of the write concern error.写入关注错误原因的描述。
WriteResult.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:写入关注对象还可以包含以下字段,指示写入关注的来源:WriteResult.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.在没有所有其他写入关注规范的情况下,写入关注源自服务器。