|
| 1 | +# Create Database Operation |
| 2 | +--- |
| 3 | + |
| 4 | +{NOTE: } |
| 5 | + |
| 6 | +* Use `CreateDatabaseOperation` to create a new database from the **Client API**, as described below. |
| 7 | + To create a new database from the **Studio**, see [Create database](../../../studio/database/create-new-database/general-flow). |
| 8 | + |
| 9 | +* This operation requires a client certificate with a security clearance of _Operator_ or _ClusterAdmin_. |
| 10 | + To learn which operations are allowed at each level, see [Security clearance and permissions](../../../server/security/authorization/security-clearance-and-permissions). |
| 11 | + |
| 12 | +* In this article: |
| 13 | + * [Create new database](../../../client-api/operations/server-wide/create-database#create-new-database) |
| 14 | + * [Example I - Create database](../../../client-api/operations/server-wide/create-database#example-i---create-non-sharded-database) |
| 15 | + * [Example II - Ensure database does not exist before creating](../../../client-api/operations/server-wide/create-database#example-ii---ensure-database-does-not-exist-before-creating) |
| 16 | + * [Syntax](../../../client-api/operations/server-wide/create-database#syntax) |
| 17 | + |
| 18 | +{NOTE/} |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +{PANEL: Create new database} |
| 23 | + |
| 24 | +{CONTENT-FRAME: } |
| 25 | + |
| 26 | +##### Example I - Create database |
| 27 | +--- |
| 28 | + |
| 29 | +* The following simple example creates a non-sharded database with the default replication factor of 1. |
| 30 | + |
| 31 | +{CODE:java CreateDatabase@ClientApi\Operations\Server\CreateDeleteDatabase.java /} |
| 32 | + |
| 33 | +{CONTENT-FRAME/} |
| 34 | +{CONTENT-FRAME: } |
| 35 | + |
| 36 | +##### Example II - Ensure database does not exist before creating |
| 37 | +--- |
| 38 | + |
| 39 | +* To ensure the database does not already exist before creating it, follow this example: |
| 40 | + |
| 41 | +{CODE:java EnsureDatabaseExists@ClientApi\Operations\Server\CreateDeleteDatabase.java /} |
| 42 | + |
| 43 | +{CONTENT-FRAME/} |
| 44 | +{PANEL/} |
| 45 | + |
| 46 | +{PANEL: Syntax} |
| 47 | + |
| 48 | +{CODE:java create_database_syntax@ClientApi\Operations\Server\CreateDeleteDatabase.java /} |
| 49 | + |
| 50 | +| Parameter | Type | Description | |
| 51 | +|-----------------------|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 52 | +| **databaseRecord** | DatabaseRecord | Instance of `DatabaseRecord` containing database configuration. | |
| 53 | +| **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. | |
| 54 | + |
| 55 | +## DatabaseRecord |
| 56 | + |
| 57 | +`DatabaseRecord` is a collection of database configurations. |
| 58 | + |
| 59 | +| constructor | Description | |
| 60 | +|---------------------------------------|----------------------------------| |
| 61 | +| DatabaseRecord(`string` databaseName) | Initialize a new database record | |
| 62 | + |
| 63 | +{INFO: } |
| 64 | + |
| 65 | +**Note:** |
| 66 | + |
| 67 | +* Only the properties listed in the table below can be configured in the `DatabaseRecord` object passed to `CreateDatabaseOperation`. |
| 68 | +* For example, although ongoing task definitions are public on the _DatabaseRecord_ class, setting them during database creation will result in an exception. |
| 69 | + To define ongoing tasks (e.g., backups, ETL, replication), use the appropriate dedicated operation after the database has been created. |
| 70 | + |
| 71 | +{INFO/} |
| 72 | + |
| 73 | +| Property | Type | Description | |
| 74 | +|------------------------------------|----------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 75 | +| **analyzers** | `Map<String, AnalyzerDefinition>` | A dictionary defining the [Custom Analyzers](../../../indexes/using-analyzers#creating-custom-analyzers) available to the database. | |
| 76 | +| **autoIndexes** | `Map<String, AutoIndexDefinition>` | Auto-index definitions for the database. | |
| 77 | +| **client** | `ClientConfiguration` | [Client behavior](../../../studio/server/client-configuration) configuration. | |
| 78 | +| **conflictSolverConfig** | `ConflictSolver` | Define the strategy used to resolve [Replication conflicts](../../../server/clustering/replication/replication-conflicts). | |
| 79 | +| **dataArchival** | `DataArchivalConfiguration` | [Data Archival](../../../server/extensions/archival) configuration for the database. | |
| 80 | +| **databaseName** | `String` | The database name. | |
| 81 | +| **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](../../../client-api/operations/server-wide/toggle-databases-state). | |
| 82 | +| **documentsCompression** | `DocumentsCompressionConfiguration` | Configuration settings for [Compressing documents](../../../server/storage/documents-compression). | |
| 83 | +| **elasticSearchConnectionStrings** | `Map<String, ElasticSearchConnectionString>` | Define [ElasticSearch Connection Strings](../../../client-api/operations/maintenance/connection-strings/add-connection-string#add-an-elasticsearch-connection-string), keyed by name. | |
| 84 | +| **encrypted** | `boolean` (default: false) | `true` - create an [Encrypted database](../../../server/security/encryption/database-encryption).<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. | |
| 85 | +| **expiration** | `ExpirationConfiguration` | [Expiration](../../../server/extensions/expiration) configuration for the database. | |
| 86 | +| **indexes** | `Map<String, IndexDefinition>` | Define [Indexes](../../../client-api/operations/maintenance/indexes/put-indexes) that will be created with the database - <br>no separate deployment needed. | |
| 87 | +| **integrations** | `IntegrationConfigurations` | Configuration for [Integrations](../../../integrations/postgresql-protocol/overview),<br>e.g. `PostgreSqlConfiguration`. | |
| 88 | +| **lockMode** | `DatabaseLockMode` | Set the database lock mode.<br>(default: `Unlock`)<br><br>This can be modified later via `SetDatabasesLockOperation`. | |
| 89 | +| **olapConnectionStrings** | `Map<String, OlapConnectionString>` | Define [OLAP Connection Strings](../../../client-api/operations/maintenance/connection-strings/add-connection-string#add-an-olap-connection-string), keyed by name. | |
| 90 | +| **queueConnectionStrings** | `Map<String, QueueConnectionString>` | Define [Queue Connection Strings](../../../server/ongoing-tasks/etl/queue-etl/overview), keyed by name. | |
| 91 | +| **ravenConnectionStrings** | `Map<String, RavenConnectionString>` | Define [Raven Connection Strings](../../../client-api/operations/maintenance/connection-strings/add-connection-string#add-a-ravendb-connection-string), keyed by name. | |
| 92 | +| **refresh** | `RefreshConfiguration` | [Refresh](../../../server/extensions/refresh) configuration for the database. | |
| 93 | +| **revisions** | `RevisionsConfiguration` | [Revisions](../../../document-extensions/revisions/client-api/operations/configure-revisions) configuration for the database. | |
| 94 | +| **revisionsForConflicts** | `RevisionsCollectionConfiguration` | Set the revisions configuration for conflicting documents. | |
| 95 | +| **rollingIndexes** | `Map<String, RollingIndex>` | Dictionary mapping index names to their deployment configurations. | |
| 96 | +| **settings** | `Map<String, String>` | [Configuration](../../../server/configuration/configuration-options) settings for the database. | |
| 97 | +| **sharding** | `ShardingConfiguration` | The sharding configuration. | |
| 98 | +| **sorters** | `Map<String, SorterDefinition>` | A dictionary defining the [Custom Sorters](../../../studio/database/settings/custom-sorters) available to the database. | |
| 99 | +| **sqlConnectionStrings** | `Map<String, SqlConnectionString>` | Define [SQL Connection Strings](../../../client-api/operations/maintenance/connection-strings/add-connection-string#add-an-sql-connection-string), keyed by name. | |
| 100 | +| **studio** | `StudioConfiguration` | [Studio Configuration](../../../studio/database/settings/studio-configuration). | |
| 101 | +| **timeSeries** | `TimeSeriesConfiguration` | [Time series](../../../studio/database/settings/time-series-settings) configuration for the database. | |
| 102 | +| **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`. | |
| 103 | +| **unusedDatabaseIds** | `Set<String>` | Set database IDs that will be excluded when creating new change vectors. | |
| 104 | + |
| 105 | +{PANEL/} |
| 106 | + |
| 107 | +## Related Articles |
| 108 | + |
| 109 | +- [Distributed Database](../../../server/clustering/distribution/distributed-database) |
| 110 | +- [Create Database via Studio](../../../studio/database/create-new-database/general-flow) |
0 commit comments