Language
C# Java Python
Article For
1.0 2.0 2.5

Session: Opening a Session

To open session use the openSession() method from DocumentStore instance.

Syntax

There are three overloads of openSession() methods

// Open session for a 'default' database configured in the 'DocumentStore' instance
store.openSession();

// Open session for a specified database
store.openSession("Database1"); // database name string

store.openSession({
    database: "Db1",    // string (optional, defaults to 'default' database)
    requestExecutor	    // RequestExecutor instance (optional)
});

The first method is an equivalent of doing:

store.openSession({});

The second method is an equivalent of doing:

const sessionOptions = { database: databaseName };
store.openSession(sessionOptions);

Here is the list of available SessionOption object properties:

Options
database string name of database
requestExecutor RequestExecutor RequestExecutor instance
Return Value
IDocumentSession session instance

Example

store.openSession();
// code here