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

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.

new DocumentStore(urls, [database], [authOptions]);

Important

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

const store = new DocumentStore(["http://localhost:8080"], "Northwind");
store.initialize();

The above snippet is going to instantiate a communication channel between your application and the local RavenDB server instance.

Initialization

A DocumentStore instance must be initialized before use by calling the .initialize() method.

Conventions

After DocumentStore initialization, the conventions are frozen - modification attempts are going to result with error. Conventions 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 (a singleton - simple to achieve in Node.js by wrapping it in a module). Typical initialization of a document store looks as follows:

// documentStoreHolder.js
const store = new DocumentStore("http://localhost:8080", "Northwind");
store.initialize();
export { store as documentStore }; 

Note

If you use more than one instance of DocumentStore, you should dispose it after use by calling its .dispose() method.