Monday, 5 July 2021

ArangoDB: Create new database

‘db._createDatabase(name, options, users)’ statement is used to create a database.

 

Syntax

db._createDatabase(name, options, users)

 

Example

db._createDatabase("demodb", {}, [{ username: "demouser", passwd: "tiger", active: true}])

 

‘options’ attribute is used to set some defaults for a collection. Following table summarizes the different options supported by createDatabase method.

Option

Description

sharding

Specifies the sharding method to use. Valid values are: "" or "single". Setting this option to "single" will enable the OneShard feature in the Enterprise Edition.

replicationFactor

Valid values are

a.   "satellite", which will replicate the collection to every DB-Server

b.   1, which disables replication.

writeConcern

Specifies how many copies of each shard are required to be in sync on the different DB-Servers.

 

The value of writeConcern must less than or equal to replicationFactor.

 

‘users’ attribute is used to set initial users to use this database. Following table summarizes the valid attributes for users.

 

Attribute

Description

username

User name to connect to this database

passwd

Password to connect to this database

active

Specifies whether the user account should be active or not.

extra

Optional json object to represent any additional information.

 

 

Step 1: Login to arango shell.

$arangosh
Please specify a password: 

                                       _     
  __ _ _ __ __ _ _ __   __ _  ___  ___| |__  
 / _` | '__/ _` | '_ \ / _` |/ _ \/ __| '_ \ 
| (_| | | | (_| | | | | (_| | (_) \__ \ | | |
 \__,_|_|  \__,_|_| |_|\__, |\___/|___/_| |_|
                       |___/                 

arangosh (ArangoDB 3.7.11 [darwin] 64bit, using build , VPack 0.1.33, RocksDB 6.8.0, ICU 64.2, V8 7.9.317, OpenSSL 1.1.1k  25 Mar 2021)
Copyright (c) ArangoDB GmbH

Command-line history will be persisted when the shell is exited. You can use `--console.history false` to turn this off
Connected to ArangoDB 'http+tcp://127.0.0.1:8529, version: 3.7.11 [SINGLE, server], database: '_system', username: 'root'

Type 'tutorial' for a tutorial or 'help' to see common examples
127.0.0.1:8529@_system>

 

Step 2: Execute the statement ‘db._createDatabase("demodb", {}, [{ username: "demouser", passwd: "tiger", active: true}])’ to create new database demodb.

127.0.0.1:8529@_system> db._createDatabase("demodb", {}, [{ username: "demouser", passwd: "tiger", active: true}]);
true

 

You can execute the statement ‘db._databases();’ to list all the databases.

127.0.0.1:8529@_system> db._databases();
[ 
  "_system", 
  "demodb", 
  "example" 
]

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment