You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: Opening a session

To open synchronous session use open_session method from documentstore.

Syntax

# Open session for a 'default' database configured in 'documentstore'
with store.open_session() as session:
    session.load("doc/1")
    # code here

# Open session for a specific database
with store.open_session(database="Your database") as session:
    session.load("doc/2")
    # code here

# Open session with request_executor
request_executor = RequestsExecutor(database_name="Your database", certificate=None)
with DocumentStore.open_session(request_executor=request_executor) as session:
    session.load("doc/3")
    # code here
Parameters
database str The name of the database (default value is None)
requests_executor RequestsExecutor The requests executor (default value is None)
Return Value
DocumentSession Implements Unit of Work for accessing the RavenDB server

Remarks

with statement can be used when open a session