MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / bind

Method bind

pymongo/synchronous/client_session.py:598–614  ·  view source on GitHub ↗

Bind this session so it is implicitly passed to all database operations within the returned context. .. code-block:: python with client.start_session() as s: with s.bind(): # session=s is passed implicitly client.db.collection

(self, end_session: bool = True)

Source from the content-addressed store, hash-verified

596 raise InvalidOperation("Cannot use ended session")
597
598 def bind(self, end_session: bool = True) -> _BoundSessionContext:
599 """Bind this session so it is implicitly passed to all database operations within the returned context.
600
601 .. code-block:: python
602
603 with client.start_session() as s:
604 with s.bind():
605 # session=s is passed implicitly
606 client.db.collection.insert_one({"x": 1})
607
608 :param end_session: Whether to end the session on exiting the returned context. Defaults to True.
609 If set to False, :meth:`~pymongo.client_session.ClientSession.end_session()` must be called
610 once the session is no longer used.
611
612 .. versionadded:: 4.17
613 """
614 return _BoundSessionContext(self, end_session)
615
616 def __enter__(self) -> ClientSession:
617 return self

Callers 6

_test_opsMethod · 0.45
_test_opsMethod · 0.45

Calls 1

Tested by 6

_test_opsMethod · 0.36
_test_opsMethod · 0.36