ArangoDB v3.10 reached End of Life (EOL) and is no longer supported.

This documentation is outdated. Please see the most recent stable version.

The @arangodb/aql/queries module of the JavaScript API

The query module provides the infrastructure for working with currently running AQL queries via arangosh

const queries = require('@arangodb/aql/queries')

Properties

queries.properties() Returns the servers current query tracking configuration; we change the slow query threshold to get better results:

var queries = require("@arangodb/aql/queries");
queries.properties();
queries.properties({slowQueryThreshold: 1});
queries.properties({slowStreamingQueryThreshold: 1});
Show output

Currently running queries

We create a task that spawns queries, so we have nice output. Since this task uses resources, you may want to increase period (and not forget to remove it… afterwards):

var theQuery = 'FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong';
var tasks = require("@arangodb/tasks");
tasks.register({
  id: "mytask-1",
  name: "this is a sample task to spawn a slow aql query",
  command: "require('@arangodb').db._query('" + theQuery + "');"
});
queries.current();
Show output

Slow queries

The function returns the last AQL queries that exceeded the slow query threshold as an array:

queries.slow();

Clear slow queries

Clear the list of slow AQL queries:

queries.clearSlow();
queries.slow();
Show output

Kill

Kill a running AQL query:

var runningQueries = queries.current().filter(function(query) {
  return query.query === theQuery;
});
queries.kill(runningQueries[0].id);
Show output