-
Notifications
You must be signed in to change notification settings - Fork 26
DOCSP-49811 - ClientSessionOptions #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mongoKart
merged 7 commits into
mongodb:docsp-45382-comp-cvg
from
mongoKart:docsp-49811-clientSessionOptions
May 8, 2025
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,15 +1,15 @@ | ||||||
.. _csharp-transactions: | ||||||
|
||||||
============ | ||||||
Transactions | ||||||
============ | ||||||
================================ | ||||||
Batch Operations in Transactions | ||||||
================================ | ||||||
|
||||||
.. facet:: | ||||||
:name: genre | ||||||
:values: reference | ||||||
|
||||||
.. meta:: | ||||||
:keywords: code example, multi-document | ||||||
:keywords: code example, multi-document, atomic, acid | ||||||
|
||||||
.. contents:: On this page | ||||||
:local: | ||||||
|
@@ -27,28 +27,93 @@ transaction is committed. If any operation in the transaction returns an | |||||
error, the driver cancels the transaction and discards all data changes | ||||||
before they ever become visible. | ||||||
|
||||||
MongoDB guarantees that the data involved in your transaction operations remains | ||||||
consistent, even if the operations encounter unexpected errors. | ||||||
|
||||||
Sessions | ||||||
-------- | ||||||
|
||||||
In MongoDB, transactions run within logical **sessions**. A | ||||||
:manual:`session </reference/server-sessions/>` is a grouping of related | ||||||
read or write operations that you intend to run sequentially. Sessions | ||||||
enable :manual:`causal consistency | ||||||
</core/read-isolation-consistency-recency/#causal-consistency>` for a | ||||||
enable causal consistency for a | ||||||
group of operations or allow you to execute operations in an | ||||||
:website:`ACID transaction </basics/acid-transactions>`. MongoDB | ||||||
guarantees that the data involved in your transaction operations remains | ||||||
consistent, even if the operations encounter unexpected errors. | ||||||
:website:`ACID transaction </basics/acid-transactions>`. | ||||||
|
||||||
When using the {+driver-short+}, you can create a new session from a | ||||||
``MongoClient`` instance as an ``IClientSession`` type. We recommend that you reuse | ||||||
your client for multiple sessions and transactions instead of | ||||||
instantiating a new client each time. | ||||||
|
||||||
The following example shows how to create a session by calling the ``StartSession()`` | ||||||
method: | ||||||
|
||||||
.. code-block:: | ||||||
|
||||||
var client = new MongoClient("mongodb://localhost:27017"); | ||||||
var session = client.StartSession(); | ||||||
|
||||||
.. warning:: | ||||||
|
||||||
Use an ``IClientSession`` only with the ``MongoClient`` (or associated | ||||||
``MongoDatabase`` or ``MongoCollection``) that created it. Using an | ||||||
``IClientSession`` with a different ``MongoClient`` results in operation | ||||||
errors. | ||||||
|
||||||
ClientSessionOptions | ||||||
~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
You can customize the behavior of your session by passing an instance of the | ||||||
``ClientSessionOptions`` class to the ``StartSession()`` method. The following table | ||||||
describes the properties that you can set on a ``ClientSessionOptions`` object: | ||||||
|
||||||
.. list-table:: | ||||||
:widths: 20 80 | ||||||
:header-rows: 1 | ||||||
|
||||||
* - Property | ||||||
- Description | ||||||
|
||||||
* - ``CausalConsistency`` | ||||||
- Specifies whether the session is causally consistent. In a causally consistent session, | ||||||
the driver executes operations in the order they were issued. To learn more, see | ||||||
:ref:`<csharp-causal-consistency>`. | ||||||
| | ||||||
| **Data Type**: {+bool-data-type+} | ||||||
| **Default**: ``true`` | ||||||
mongoKart marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
* - ``DefaultTransactionOptions`` | ||||||
- The default transaction options for the session. This includes the maximum commit | ||||||
|
- The default transaction options for the session. This includes the maximum commit | |
- Specifies the default transaction options for the session. This includes the maximum commit |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: add the language here; also applies to the other code block