Docs HomeMongoDB Manual

WriteResult()

On this page本页内容

Definition定义

WriteResult()

A wrapper that contains the result status of mongosh write 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 using db.collection.bulkWrite().对于类似于WriteResult()的输出,请考虑使用db.collection.bulkWrite()

Properties属性

The WriteResult() has the following properties:WriteResult()具有以下属性:

WriteResult.nInserted

The number of documents inserted, excluding upserted documents. 插入的文档数,不包括upserted的文档。See WriteResult.nUpserted for the number of documents inserted through an upsert.有关通过追加插入的文档数,请参阅WriteResult.nUpserted

WriteResult.nMatched

The number of documents selected for update. 选择要更新的文档数。If the update operation results in no change to the document, e.g. $set expression updates the value to the current value, nMatched can be greater than nModified.如果更新操作导致文档没有更改,例如$set表达式将值更新为当前值,则nMatched可以大于nModified

WriteResult.nModified

The 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, nModified can be less than nMatched.如果更新/替换操作未导致文档发生更改,例如将字段的值设置为当前值,则nModified可以小于nMatched

WriteResult.nUpserted

The number of documents inserted by an upsert.追加upsert的文档数。

WriteResult._id

The _id of the document inserted by an upsert. upsert插入的文档的_idReturned only if an upsert results in an insert.仅当upsert导致插入时才返回。

WriteResult.nRemoved

The number of documents removed.删除的文档数。

WriteResult.writeError

A document that contains information regarding any error, excluding write concern errors, encountered during the write operation.一种文档,包含有关写入操作期间遇到的任何错误(不包括写入关注错误)的信息。

WriteResult.writeError.code

An integer value identifying the error.标识错误的整数值。

WriteResult.writeError.errmsg

A description of the error.错误的描述。

WriteResult.writeConcernError

A document that contains information regarding any write concern errors encountered during the write operation.一种文档,包含有关写入操作期间遇到的任何写入关注错误的信息。

WriteResult.writeConcernError.code

An integer value identifying the cause of the write concern error.一个整数值,用于标识写入关注错误的原因。

WriteResult.writeConcernError.errmsg

A description of the cause of the write concern error.写入关注错误原因的描述。

WriteResult.writeConcernError.errInfo.writeConcern

New in version 4.4. 4.4版新增。

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:写入关注对象还可能包含以下字段,指示写入关注的来源:

WriteResult.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.在没有所有其他写入关注规范的情况下,写入关注源自服务器。