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

Mongo.startSession()(mongoshメソッド)

Mongo.startSession(<options>)

Starts a session for the connection. mongosh assigns the session ID to commands associated with the session.

重要

mongosh メソッド

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

データベースコマンドについては、startSession コマンドを参照してください。

MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。

セッションは、セッションを作成したMongoClientオブジェクトでのみ使用できます。 1 つのセッションを同時に使用することはできません。 1 つのセッションを使用する操作は連続して実行する必要があります。

The startSession() method can take a document with session options. The options available are:

フィールド
説明

因果整合性

Boolean. Enables or disables causal consistency for the session. Mongo.startSession() enables causalConsistency by default.

セッションを開始した後は、そのcausalConsistency設定を変更することはできません。

Mongo()接続オブジェクトで因果整合性が無効になっている場合でも、セッションでは因果整合性が有効になっている場合や、 接続オブジェクトに因果整合性を設定するには、 Mongo.setCausalConsistency()を参照してください。

ReadConcern

ドキュメント。 読み取り保証 ( read concern) を指定します。

セッションを開始した後に設定を変更するには、 Session.getOptions().setReadConcern()を参照してください。

readPreference

ドキュメント。 読み込み設定 ( read preference) を指定します。

readPreference ドキュメントには、 modeフィールドと任意のtagsフィールドが含まれています。

{ mode: <string>, tags: <array> }

セッションを開始した後に設定を変更するには、 Session.getOptions().setReadPreference()を参照してください。

retryWrites

ブール値。 一時的なネットワークエラーが発生したときに書き込みを再試行する機能を有効または無効にします。

If you start mongosh with the --retryWrites option, retryWrites is enabled by default for Mongo.startSession().

セッションを開始した後は、そのretryWrites設定を変更することはできません。

writeConcern

ドキュメント。 書込み保証 ( write concern) を指定します。

セッションを開始した後に設定を変更するには、 Session.getOptions().setWriteConcern()を参照してください。

The following starts a session with causal consistency and retryable writes enabled on the Mongo() connection object associated with mongosh's global db variable:

db = db.getMongo().startSession({retryWrites: true, causalConsistency: true}).getDatabase(db.getName());
このページを評価

項目一覧