---
title: "Create Database Operation"
url: "https://docs.ravendb.net/6.2/client-api/operations/server-wide/create-database"
version: "6.2"
language: "java"
---

# Create Database Operation

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/server-wide/create-database.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."

> **Note**
>
> - Use `CreateDatabaseOperation` to create a new database from the **Client API**, as described below.  
>   To create a new database from the **Studio**, see [Create database](https://docs.ravendb.net/6.2/studio/database/create-new-database/general-flow.md).
>
> - This operation requires a client certificate with a security clearance of *Operator* or *ClusterAdmin*.  
>   To learn which operations are allowed at each level, see [Security clearance and permissions](https://docs.ravendb.net/6.2/server/security/authorization/security-clearance-and-permissions.md).
>
> - In this article:
>   - [Create new database](#create-new-database)
>     - [Example I - Create database](#example-i---create-non-sharded-database)
>     - [Example II - Ensure database does not exist before creating](#example-ii---ensure-database-does-not-exist-before-creating)
>   - [Syntax](#syntax)

## Create new database

> **Note**
>
> ##### Example I - Create database
>
> - The following simple example creates a non-sharded database with the default replication factor of 1.
>
> ```java
> DatabaseRecord databaseRecord = new DatabaseRecord();
> databaseRecord.setDatabaseName("MyNewDatabase");
> store.maintenance().server().send(new CreateDatabaseOperation(databaseRecord));
> ```

> **Note**
>
> ##### Example II - Ensure database does not exist before creating
>
> - To ensure the database does not already exist before creating it, follow this example:
>
> ```java
> public void ensureDatabaseExists(IDocumentStore store, String database, boolean createDatabaseIfNotExists) {
>   database = ObjectUtils.firstNonNull(database, store.getDatabase());
>
>   if (StringUtils.isBlank(database)) {
>       throw new IllegalArgumentException("Value cannot be null or whitespace");
>   }
>
>   try {
>       store.maintenance().forDatabase(database).send(new GetStatisticsOperation());
>   } catch (DatabaseDoesNotExistException e) {
>       if (!createDatabaseIfNotExists) {
>           throw e;
>       }
>
>       try {
>           DatabaseRecord databaseRecord = new DatabaseRecord();
>           databaseRecord.setDatabaseName(database);
>           store.maintenance().server().send(new CreateDatabaseOperation(databaseRecord));
>       } catch (ConcurrencyException ce) {
>           // The database was already created before calling CreateDatabaseOperation
>       }
>   }
> }
> ```

## Syntax

```java
public CreateDatabaseOperation(DatabaseRecord databaseRecord)

public CreateDatabaseOperation(DatabaseRecord databaseRecord, int replicationFactor)
```

| Parameter | Type | Description |
| - | - | - |
| **databaseRecord** | DatabaseRecord | Instance of `DatabaseRecord` containing database configuration. |
| **replicationFactor** | int | Number of nodes the database should be replicated to.<br /><br />If not specified, the value is taken from `topology.replicationFactor`,<br />or defaults to **`1`** if that is not set.<br /><br />If `topology` is provided, the `replicationFactor` is ignored. |

## DatabaseRecord

`DatabaseRecord` is a collection of database configurations.

| constructor | Description |
| - | - |
| DatabaseRecord(`string` databaseName) | Initialize a new database record |

> **Info**
>
> **Note:**
>
> - Only the properties listed in the table below can be configured in the `DatabaseRecord` object passed to `CreateDatabaseOperation`.
> - For example, although ongoing task definitions are public on the *DatabaseRecord* class, setting them during database creation will result in an exception.
>   To define ongoing tasks (e.g., backups, ETL, replication), use the appropriate dedicated operation after the database has been created.

| Property | Type | Description |
| - | - | - |
| **analyzers** | `Map<String, AnalyzerDefinition>` | A dictionary defining the [Custom Analyzers](https://docs.ravendb.net/6.2/indexes/using-analyzers.java.md#creating-custom-analyzers) available to the database. |
| **autoIndexes** | `Map<String, AutoIndexDefinition>` | Auto-index definitions for the database. |
| **client** | `ClientConfiguration` | [Client behavior](https://docs.ravendb.net/6.2/studio/server/client-configuration.md) configuration. |
| **conflictSolverConfig** | `ConflictSolver` | Define the strategy used to resolve [Replication conflicts](https://docs.ravendb.net/6.2/server/clustering/replication/replication-conflicts.md). |
| **dataArchival** | `DataArchivalConfiguration` | [Data Archival](https://docs.ravendb.net/6.2/data-archival/overview.md) configuration for the database. |
| **databaseName** | `String` | The database name. |
| **disabled** | `boolean` (default: false) | Set the database initial state.<br /> `true` - disable the database.<br /> `false` - (default) the database will be enabled.<br /><br />This can be modified later via [ToggleDatabasesStateOperation](https://docs.ravendb.net/6.2/client-api/operations/server-wide/toggle-databases-state.md). |
| **documentsCompression** | `DocumentsCompressionConfiguration` | Configuration settings for [Compressing documents](https://docs.ravendb.net/6.2/server/storage/documents-compression.md). |
| **elasticSearchConnectionStrings** | `Map<String, ElasticSearchConnectionString>` | Define [ElasticSearch Connection Strings](https://docs.ravendb.net/6.2/client-api/operations/maintenance/connection-strings/add-connection-string.md#add-an-elasticsearch-connection-string), keyed by name. |
| **encrypted** | `boolean` (default: false) | `true` - create an [Encrypted database](https://docs.ravendb.net/6.2/server/security/encryption/database-encryption.md).<br /><br />Note: Use `PutSecretKeyCommand` to send your secret key to the server BEFORE creating the database.<br /><br />`false` - (default) the database will not be encrypted. |
| **expiration** | `ExpirationConfiguration` | [Expiration](https://docs.ravendb.net/6.2/server/extensions/expiration.md) configuration for the database. |
| **indexes** | `Map<String, IndexDefinition>` | Define [Indexes](https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/put-indexes.java.md) that will be created with the database - <br />no separate deployment needed. |
| **integrations** | `IntegrationConfigurations` | Configuration for [Integrations](https://docs.ravendb.net/6.2/integrations/postgresql-protocol/overview.md),<br />e.g. `PostgreSqlConfiguration`. |
| **lockMode** | `DatabaseLockMode` | Set the database lock mode.<br />(default: `Unlock`)<br /><br />This can be modified later via `SetDatabasesLockOperation`. |
| **olapConnectionStrings** | `Map<String, OlapConnectionString>` | Define [OLAP Connection Strings](https://docs.ravendb.net/6.2/client-api/operations/maintenance/connection-strings/add-connection-string.md#add-an-olap-connection-string), keyed by name. |
| **queueConnectionStrings** | `Map<String, QueueConnectionString>` | Define [Queue Connection Strings](https://docs.ravendb.net/6.2/server/ongoing-tasks/etl/queue-etl/overview.md), keyed by name. |
| **ravenConnectionStrings** | `Map<String, RavenConnectionString>` | Define [Raven Connection Strings](https://docs.ravendb.net/6.2/client-api/operations/maintenance/connection-strings/add-connection-string.md#add-a-ravendb-connection-string), keyed by name. |
| **refresh** | `RefreshConfiguration` | [Refresh](https://docs.ravendb.net/6.2/server/extensions/refresh.md) configuration for the database. |
| **revisions** | `RevisionsConfiguration` | [Revisions](https://docs.ravendb.net/6.2/document-extensions/revisions/client-api/operations/configure-revisions.java.md) configuration for the database. |
| **revisionsForConflicts** | `RevisionsCollectionConfiguration` | Set the revisions configuration for conflicting documents. |
| **rollingIndexes** | `Map<String, RollingIndex>` | Dictionary mapping index names to their deployment configurations. |
| **settings** | `Map<String, String>` | [Configuration](https://docs.ravendb.net/6.2/server/configuration/configuration-options.md) settings for the database. |
| **sharding** | `ShardingConfiguration` | The sharding configuration. |
| **sorters** | `Map<String, SorterDefinition>` | A dictionary defining the [Custom Sorters](https://docs.ravendb.net/6.2/studio/database/settings/custom-sorters.md) available to the database. |
| **sqlConnectionStrings** | `Map<String, SqlConnectionString>` | Define [SQL Connection Strings](https://docs.ravendb.net/6.2/client-api/operations/maintenance/connection-strings/add-connection-string.md#add-an-sql-connection-string), keyed by name. |
| **studio** | `StudioConfiguration` | [Studio Configuration](https://docs.ravendb.net/6.2/studio/database/settings/studio-configuration.md). |
| **timeSeries** | `TimeSeriesConfiguration` | [Time series](https://docs.ravendb.net/6.2/studio/database/settings/time-series-settings.md) configuration for the database. |
| **topology** | `DatabaseTopology` | Optional topology configuration.<br /><br />Defaults to `null`, in which case the server will determine which nodes to place the database on, based on the specified `ReplicationFactor`. |
| **unusedDatabaseIds** | `Set<String>` | Set database IDs that will be excluded when creating new change vectors. |

## See also

- [Distributed Database](https://docs.ravendb.net/6.2/server/clustering/distribution/distributed-database.md)
- [Create Database via Studio](https://docs.ravendb.net/6.2/studio/database/create-new-database/general-flow.md)
