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 はクラウドでの MongoDB 配置のための完全管理サービスです
  • 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によって挿入されたドキュメントのupsertupsertの結果が挿入された場合にのみ返されます。

WriteResult.nRemoved

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

WriteResult.writeError

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

WriteResult.writeError.code

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

WriteResult.writeError.errmsg

エラーの説明です。

WriteResult.writeConcernError

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

バージョン 7.0.6 での変更

および でも利用可能6.0.145.0.30 ):WriteResult()mongos から受信されると、1 つ以上の書込みエラーが発生しても、書込み保証 (write concern)エラーが常に報告されます。以前のリリースでは、書込みエラーが発生すると、 は書込み保証WriteResult() (write concern)エラーを報告しないことがありました。

各エラー ドキュメントには以下のフィールドが含まれます。

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)が一切指定されていない状態で、サーバーから発生した書き込み保証。

このページを評価