对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

WriteResult()(mongosh方法)

WriteResult()

A wrapper that contains the result status of mongosh write methods.

注意

db.collection.insert()db.collection.update() 已弃用。

The results returned by the replacement methods have a different format. For output similar to WriteResult(), consider using db.collection.bulkWrite().

此方法可用于以下环境中托管的部署:

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

The WriteResult() has the following properties:

WriteResult.nInserted

The number of documents inserted, excluding upserted documents. See WriteResult.nUpserted for the number of documents inserted through an upsert.

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.

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.

WriteResult.nUpserted

upsert 插入的文档数。

WriteResult._id

通过 upsert 插入的文档的 _id。仅当 upsert 导致插入时返回。

WriteResult.nRemoved

删除的文档数。

WriteResult.writeError

包含写入操作过程中遇到的任何错误(不包括写关注错误)的相关信息的文档。

WriteResult.writeError.code

标识错误的整数值。

WriteResult.writeError.errmsg

错误描述。

WriteResult.writeConcernError

描述与写关注(write concern)相关的错误的文档。

在版本 7.0.6 中进行了更改:

(也适用于 6.0.14和5.0.30 ):当从WriteResult() 收到mongos 时,即使出现一个或多个写入错误,也始终会报告写关注(write concern)错误。在以前的版本中,发生写入错误可能会导致WriteResult() 不报告写关注(write concern)错误。

每个错误文档都包含以下字段:

WriteResult.writeConcernError.code

一个整数值,用于标识写关注错误原因。

WriteResult.writeConcernError.errmsg

写关注错误原因的描述。

WriteResult.writeConcernError.errInfo.writeConcern

用于相应操作的写关注对象。有关写关注对象字段的信息,请参阅写关注规范

写关注对象还可能包含以下字段,指示写关注的来源:

WriteResult.writeConcernError.errInfo.writeConcern.provenance

一个表示写关注来源(称为写关注provenance)的字符串值。下表显示该字段的可能值及其有效位数:

来源
说明

clientSupplied

应用程序中指定了写关注。

customDefault

写入关注源自自定义的默认值。请参阅 setDefaultRWConcern

getLastErrorDefaults

写关注源自副本集的 settings.getLastErrorDefaults 字段。

implicitDefault

在没有所有其他写入关注规范的情况下,写入关注源自服务器。

给本页内容打分

在此页面上