ArangoDB Shell Introduction

    The arangosh binary is shipped with ArangoDB. It offers a JavaScript shellenvironment providing access to the ArangoDB server.Arangosh can be invoked like this:

    By default arangosh will try to connect to an ArangoDB server running onserver localhost on port 8529. It will use the username root and anempty password by default. Additionally it will connect to the default database(_system). All these defaults can be changed using the following command-line options:

    • —server.database : name of the database to connect to
    • —server.endpoint : endpoint to connect to
    • —server.username : database username
    • —server.password : password to use when connecting
    • —server.authentication : whether or not to use authenticationFor example, to connect to an ArangoDB server on IP 192.168.173.13 on port8530 with the user foo and using the database test, use:
    1. --server.endpoint tcp://192.168.173.13:8530 \
    2. --server.username foo \
    3. --server.database test \

    arangosh will then display a password prompt and try to connect to the server after the password was entered.

    To change the current database after the connection has been made, youcan use the db._useDatabase() command in arangosh:

    1. arangosh> db._createDatabase("myapp");
    2. arangosh> db._useDatabase("myapp");
    3. arangosh> db._useDatabase("_system");
    4. arangosh> db._dropDatabase("myapp");

    Show execution results

    To get a list of available commands, arangosh provides a help() function.Calling it will display helpful information.

    arangosh also provides auto-completion. Additional information on available commands and methods is thus provided by typing the first few letters of avariable and then pressing the tab key. It is recommend to try this with enteringdb. (without pressing return) and then pressing tab.

    By the way, arangosh provides the db object by default, and this object canbe used for switching to a different database and managing collections inside thecurrent database.

    For a list of available methods for the db object, type

    1. arangosh> db._help();

    Show execution results

    1. --------------------------- ArangoDatabase (db) help ---------------------------
    2. Administration Functions:
    3. _help() this help
    4. _flushCache() flush and refill collection cache
    5.  
    6. Collection Functions:
    7. _collections() list all collections
    8. _collection(<name>) get collection by identifier/name
    9. _createEdgeCollection(<name>) creates a new edge collection
    10. _drop(<name>) delete a collection
    11.  
    12. Document Functions:
    13. _document(<id>) get document by handle (_id)
    14. _replace(<id>, <data>, <overwrite>) overwrite document
    15. _update(<id>, <data>, <overwrite>, partially update document
    16. <keepNull>)
    17. _remove(<id>) delete document
    18. _exists(<id>) checks whether a document exists
    19. _truncate() delete all documents
    20.  
    21. Database Management Functions:
    22. _createDatabase(<name>) creates a new database
    23. _dropDatabase(<name>) drops an existing database
    24. _useDatabase(<name>) switches into an existing database
    25. _drop(<name>) delete a collection
    26. _name() name of the current database
    27.  
    28. Query / Transaction Functions:
    29. _executeTransaction(<transaction>) execute transaction
    30. _query(<query>) execute AQL query
    31. _createStatement(<data>) create and return AQL query
    32.  
    33. _views() list all views
    34. _view(<name>) get view by name
    35. _createView(<name>, <type>, <properties>) creates a new view

    you can paste multiple lines into arangosh, given the first line ends with anopening brace:

    Show execution results

    1. Hello world 0!
    2.  
    3. Hello world 1!
    4.  
    5. Hello world 2!
    6.  
    7. Hello world 3!
    8.  
    9. Hello world 4!
    10.  
    11. Hello world 5!
    12.  
    13. Hello world 6!
    14.  
    15. Hello world 7!
    16.  
    17. Hello world 8!
    18.  
    19. Hello world 9!

    Hide execution results

    To load your own JavaScript code into the current JavaScript interpreter context,use the load command:

    1. require("internal").load("/tmp/test.js") // <- Linux / MacOS
    2. require("internal").load("c:\\tmp\\test.js") // <- Windows

    Exiting arangosh can be done using the key combination or bytyping quit<CR>

    You can use bind variables tomitigate this:

    1. db._query(aql`RETURN ${somepath}`)