Docs Menu

Mongo.startSession()

項目一覧

Mongo.startSession(<options>)

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

重要

mongosh メソッド

このページでは、mongosh メソッドについて記載しています。ただし、データベースコマンドや Node.js などの言語固有のドライバーのドキュメントには該当しません

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

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

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

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

フィールド
説明

causalConsistency

ブール値。 セッションの因果整合性を有効または無効にします。 Mongo.startSession() enables causalConsistency by default. Mutually exclusive with snapshot.

After starting a session, you cannot modify its causalConsistency setting.

The session may have causal consistency enabled even though the Mongo() connection object may have causal consistency disabled or vice versa. To set causal consistency on the connection object, see Mongo.setCausalConsistency().

readConcern

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

To modify the setting after starting a session, see Session.getOptions().setReadConcern().

readPreference

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

The readPreference document contains the mode field and the optional tags field:

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

To modify the setting after starting a session, see Session.getOptions().setReadPreference().

retryWrites

Boolean. Enables or disables the ability to retry writes upon encountering transient network errors.

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

After starting a session, you cannot modify its retryWrites setting.

スナップショット

Boolean. Enables snapshot reads for the session for MongoDB 5.0+ deployments. Mutually exclusive with causalConsistency.

writeConcern

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

To modify the setting after starting a session, see Session.getOptions().setWriteConcern().

このメソッドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

注意

このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

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());

項目一覧