On this page本页内容
WriteResult()
A wrapper that contains the result status of 包含mongosh
write methods.mongosh
写方法结果状态的包装器。
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()
。
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.upsert
插入的文档数,请参阅WWriteResult.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._id
The 由_id
of the document inserted by an upsert
. upsert
插入的文档的_id
。Returned only if an 仅当upsert
results in an insert.upsert
导致插入时返回。
WriteResult.writeError
A document that contains information regarding any error, excluding write concern errors, encountered during the write operation.一种文档,包含有关写入操作期间遇到的任何错误(不包括写入问题错误)的信息。
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
). provenance
)。The following table shows the possible values for this field and their significance:下表显示了该字段的可能值及其重要性:
Provenance | |
---|---|
clientSupplied | |
customDefault | setDefaultRWConcern .setDefaultRWConcern 。
|
getLastErrorDefaults | settings.getLastErrorDefaults field.settings.getLastErrorDefaults 字段。
|
implicitDefault |