Client API: How to Create a Document Store

To create an instance of the DocumentStore you need to specify a list of URL addresses that point to RavenDB server nodes.

Important

Do not open a DocumentStore using URL addresses that point to nodes outside your cluster.

try (IDocumentStore store = new DocumentStore( new String[]{ "http://localhost:8080" }, "Northwind")) {
    store.initialize();


}

This will instantiate a communication channel between your application and the local RavenDB server instance.

Initialization

To be able to work on the DocumentStore, you will have to call the initialize method to get the fully initialized instance of IDocumentStore.

Conventions

The conventions are frozen after DocumentStore initialization so they need to be set before initialize is called.

Singleton

Because the document store is a heavyweight object, there should only be one instance created per application (singleton). The document store is a thread safe object and its typical initialization looks like the following:

public static class DocumentStoreHolder {

    private static IDocumentStore store;

    static {
        store = new DocumentStore(new String[]{ "http://localhost:8080" }, "Northwind");
    }

    public static IDocumentStore getStore() {
        return store;
    }
}

Note

If you use more than one instance of DocumentStore you should dispose it after use.