Skip to content

Commit e00ac18

Browse files
committed
Add docstring example
1 parent a1234ed commit e00ac18

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

pymongo/asynchronous/client_session.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ def _check_ended(self) -> None:
573573
def bind(self, end_session: bool = True) -> _AsyncBoundSessionContext:
574574
"""Bind this session so it is implicitly passed to all database operations within the returned context.
575575
576+
.. code-block:: python
577+
578+
async with client.start_session() as s:
579+
async with s.bind():
580+
# session=s is passed implicitly
581+
await client.db.collection.insert_one({"x": 1})
582+
576583
:param end_session: Whether to end the session on exiting the returned context. Defaults to True.
577584
If set to False, :meth:`~pymongo.asynchronous.client_session.AsyncClientSession.end_session()` must be called
578585
once the session is no longer used.

pymongo/synchronous/client_session.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,13 @@ def _check_ended(self) -> None:
572572
def bind(self, end_session: bool = True) -> _BoundSessionContext:
573573
"""Bind this session so it is implicitly passed to all database operations within the returned context.
574574
575+
.. code-block:: python
576+
577+
with client.start_session() as s:
578+
with s.bind():
579+
# session=s is passed implicitly
580+
client.db.collection.insert_one({"x": 1})
581+
575582
:param end_session: Whether to end the session on exiting the returned context. Defaults to True.
576583
If set to False, :meth:`~pymongo.client_session.ClientSession.end_session()` must be called
577584
once the session is no longer used.

0 commit comments

Comments
 (0)