AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

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: The fully managed service for MongoDB deployments in the cloud
  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の 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

アップサート によって挿入されたドキュメントの数。

WriteResult._id

_idによって挿入されたドキュメントのupsert 。upsertの結果が挿入された場合にのみ返されます。

WriteResult.nRemoved

削除されたドキュメントの数。

WriteResult.writeError

書込み保証(write concern) エラーを除く、書込み操作中に発生したすべてのエラーに関する情報を含むドキュメント。

WriteResult.writeError.code

エラーを識別する整数値です。

WriteResult.writeError.errmsg

エラーの説明です。

WriteResult.writeError.errInfo

書込み (write)操作中に発生した、書込み保証 (write concern)エラーを除くすべての書込み (write) エラーに関する情報を含むドキュメントです。 操作スキーマ検証 に失敗すると、サーバーはこのフィールドの下にドキュメントがコレクションの バリデーター式と一致しなかった理由を説明するエラーを生成します。

WriteResult.writeConcernError

書込み保証 (write concern) に関連するエラーを説明するドキュメント。

バージョン 7.0.6 での変更:

(also available in 6.0.14 and 5.0.30): When WriteResult() is received from mongos, write concern errors are always reported, even when one or more write errors occur. In previous releases, the occurrence of write errors could cause the WriteResult() to not report write concern errors.

WriteResult.writeConcernError.code

書込み保証 (write concern) エラーの原因を示す整数値です。

WriteResult.writeConcernError.errmsg

書込み保証 (write concern) エラーの原因の説明です。

WriteResult.writeConcernError.errInfo.writeConcern

対応する操作に使用される書込み保証 (write concern) オブジェクトです。書込み保証 (write concern) オブジェクト フィールドの詳細については、「書込み保証 (write concern) の仕様」を参照してください。

書込み保証 (write concern) オブジェクトには、書込み保証 (write concern) のソースを示す以下のフィールドも含むことができます。

WriteResult.writeConcernError.errInfo.writeConcern.provenance

書込み保証 (write concern) が発生した場所を示す文字列値です(書込み保証 (write concern) provenance と呼ばれます)。次の表は、このフィールドに指定できる値とその意味を示しています。

出所
説明

clientSupplied

書き込み保証(write concern)がアプリケーションで指定されました。

customDefault

書込み保証 (write concern) は、カスタム定義されたデフォルト値に基づきます。setDefaultRWConcern を参照してください。

getLastErrorDefaults

書込み保証 (write concern) は、レプリカセットの settings.getLastErrorDefaults のフィールドに基づきます。

implicitDefault

他の書き込み保証(write concern)が一切指定されていない状態で、サーバーから発生した書き込み保証。

このページを評価