File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments