ArangoDB Shell Configuration

arangosh will look for a user-defined startup script named .arangosh.rc in theuser’s home directory on startup. The home directory will likely be /home/<username>/on Unix/Linux, and is determined on Windows by peeking into the environment variables%HOMEDRIVE% and %HOMEPATH%.

If the file .arangosh.rc is present in the home directory, arangosh will executethe contents of this file inside the global scope.

You can use this to define your own extra variables and functions that you need often.For example, you could put the following into the .arangosh.rc file in your homedirectory:

  1. // "var" keyword avoided intentionally...
  2. // otherwise "timed" would not survive the scope of this script
  3. global.timed = function (cb) {
  4. console.time("callback");
  5. cb();
  6. console.timeEnd("callback");
  7. };

This will make a function named timed available in arangosh in the global scope.

You can now start arangosh and invoke the function like this:

  1. timed(function () {
  2. for (var i = 0; i < 1000; ++i) {
  3. db.test.save({ value: i });
  4. }
  5. });

Please keep in mind that, if present, the .arangosh.rc file needs to contain validJavaScript code. If you want any variables in the global scope to survive you need toomit the var keyword for them. Otherwise the variables will only be visible insidethe script itself, but not outside.