Tuesday, 6 July 2021

ArangoDB: Create, update and remove users

Following commands are used to create, update and remove users.

require("@arangodb/users").save(username, password, true);
require("@arangodb/users").update(username, password, true);
require("@arangodb/users").remove(username);

 

Let’s create new user and assign it him to access example database.

 

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: Create new user test by executing below command.

require("@arangodb/users").save("test", "tiger", true);

127.0.0.1:8529@_system> require("@arangodb/users").save("test", "tiger", true);
{ 
  "user" : "test", 
  "active" : true, 
  "extra" : { 
  }, 
  "code" : 201 
}

 

Step 3: Grant access to the example database.

127.0.0.1:8529@_system> require("@arangodb/users").grantDatabase("test", "example");

 

Now you can connect to the database example using the user test.

arangosh --server.username "test" --server.database example

$arangosh --server.username "test" --server.database example
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: 'example', username: 'test'

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

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment