Working with Databases

    return the database name

    Returns the name of the current database as a string.

    Examples

    Show execution results

    Hide execution results

    1. _system

    ID

    return the database iddb._id()

    Returns the id of the current database as a string.

    Examples

      Show execution results

      Hide execution results

      1. 1

      Path

      return the path to database filesdb._path()

      Returns the filesystem path of the current database as a string.

      Examples

      Show execution results

      Hide execution results

      1. none

      return the database typedb._isSystem()

      Properties

      return the path to database filesdb._properties()

      Returns the properties of the current database as an object with the followingattributes:

      • id: the database id
      • name: the database name
      • isSystem: the database type
      • path: the path to database files
      • sharding: the sharding method to use for new collections (Cluster only)
      • replicationFactor: default replication factor for new collections(Cluster only)
      • writeConcern: a shard will refuse to write if less than this amountof copies are in sync (Cluster only)

      Examples

      1. arangosh> require("@arangodb").db._properties();

      Show execution results

      Hide execution results

      1. {
      2. "id" : "1",
      3. "name" : "_system",
      4. "isSystem" : true,
      5. "replicationFactor" : 1,
      6. "writeConcern" : 1,
      7. "path" : ""
      8. }

      Use Database

      change the current databasedb._useDatabase(name)

      Changes the current database to the database specified by name. Notethat the database specified by name must already exist.

      Changing the database might be disallowed in some contexts, for exampleserver-side actions (including Foxx).

      When performing this command from arangosh, the current credentials (usernameand password) will be re-used. These credentials might not be valid toconnect to the database specified by name. Additionally, the databaseonly be accessed from certain endpoints only. In this case, switching thedatabase might not work, and the connection / session should be closed andrestarted with different username and password credentials and/orendpoint data.

      return the list of all existing databases

      Returns the list of all databases. This method can only be used from withinthe _system database.

      Create Database

      create a new databasedb._createDatabase(name, options, users)

      Creates a new database with the name specified by name.There are restrictions for database names(see ).

      Note that even if the database is created successfully, there will be nochange into the current database to the new database. Changing the currentdatabase must explicitly be requested by using thedb._useDatabase method.

      The options attribute can be used to set defaults for collections that willbe created in the new database (Cluster only):

      • sharding: The sharding method to use. Valid values are: "" or "single".Setting this option to "single" will enable the OneShard feature in theEnterprise Edition.
      • replicationFactor: Default replication factor. Special values include"satellite", which will replicate the collection to every DB-Server, and, which disables replication.
      • writeConcern: how many copies of each shard are required to be in sync onthe different DB-Servers. If there are less then these many copies in thecluster a shard will refuse to write. The value of writeConcern can not belarger than replicationFactor.

      The optional users attribute can be used to create initial users forthe new database. If specified, it must be a list of user objects. Each userobject can contain the following attributes:

      • username: the user name as a string. This attribute is mandatory.
      • passwd: the user password as a string. If not specified, then it defaultsto an empty string.
      • active: a boolean flag indicating whether the user account should beactive or not. The default value is true.
      • extra: an optional JSON object with extra user information. The datacontained in extra will be stored for the user but not be interpretedfurther by ArangoDB.

      You can create users in a database if no initial user is specified. Switchinto the new database (username and password must be identical to the currentsession) and add or modify users with the following commands.

      Alternatively, you can specify user data directly. For example:

      1. db._createDatabase("newDB", {}, [{ username: "newUser", passwd: "123456", active: true}])

      Those methods can only be used from within the _system database.

      Drop Database

      drop an existing databasedb._dropDatabase(name)

      Drops the database specified by name. The database specified byname must exist.

      Note: Dropping databases is only possible from within the system_database. The system_ database itself cannot be dropped.

      Databases are dropped asynchronously, and will be physically removed ifall clients have disconnected and references have been garbage-collected.

      retrieve the storage engine type used by the serverdb._engine()

      Returns the name of the storage engine in use (mmfiles or rocksdb), as wellas a list of supported features (types of indexes anddfdb).

      Engine statistics

      retrieve statistics related to the storage engine (RocksDB)

      Returns some statistics related to the storage engine activity, including figuresabout data size, cache usage, etc.

      Note: Currently this only produces useful output for the RocksDB engine.

      Get the Version of ArangoDB

      db._version()

      Returns the server version string. Note that this is not the version of thedatabase.

      Examples

      1. arangosh> require("@arangodb").db._version();

      Show execution results

      1. 3.6.0-rc.2