---
title: "Client API: Setting up a Default Database"
url: "https://docs.ravendb.net/6.2/client-api/setting-up-default-database"
version: "6.2"
language: "java"
---

# Client API: Setting up a Default Database

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/setting-up-default-database.md), [Node.js](https://docs.ravendb.net/6.2/client-api/setting-up-default-database.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

`database` property allows you to setup a default database for a `DocumentStore`. Implication of setting up a default database is that each time you access [operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.java.md) or create a [session](https://docs.ravendb.net/6.2/client-api/session/what-is-a-session-and-how-does-it-work.java.md) without explicitly passing database on which they should operate on then default database is assumed.

## Example I

```java
// without specifying `database`
// we will need to specify the database in each action
// if no database is passed explicitly we will get an exception

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

  try (IDocumentSession session = store.openSession("Northwind")) {
      // ...
  }

  CompactSettings compactSettings = new CompactSettings();
  compactSettings.setDatabaseName("Northwind");
  store.maintenance().server().send(new CompactDatabaseOperation(compactSettings));
}
```

## Example II

```java
// when `database` is set to `Northwind`
// created `operations` or opened `sessions`
// will work on `Northwind` database by default
// if no database is passed explicitly
try (DocumentStore store = new DocumentStore(new String[]{ "http://localhost:8080" }, "Northwind")) {
  store.initialize();

  try (IDocumentSession northwindSession = store.openSession()) {
      // ...
  }

  store.maintenance().send(new DeleteIndexOperation("NorthwindIndex"));


  try (IDocumentSession adventureWorksSession = store.openSession("AdventureWorks")) {
      // ...
  }

  store.maintenance().forDatabase("AdventureWorks").send(new DeleteIndexOperation("AdventureWorksIndex"));
}
```

## Remarks

> **Note**
>
> By default value of `database` property in `DocumentStore` is `null` which means that in any actions that need a database name we will have to specify the database.

## See also

- [What is a Document Store](https://docs.ravendb.net/6.2/client-api/what-is-a-document-store.java.md)
- [Creating a Document Store](https://docs.ravendb.net/6.2/client-api/creating-document-store.java.md)
- [Setting up Authentication and Authorization](https://docs.ravendb.net/6.2/client-api/setting-up-authentication-and-authorization.java.md)
- [Creating a Database](https://docs.ravendb.net/6.2/studio/database/create-new-database/general-flow.md)
