1
0
Fork 0
arangodb/Documentation/Books/Drivers/JS/Reference/Database
maxkernbach d0aeff6db3 Doc - sync from external repos (#5889) 2018-07-16 18:59:44 +02:00
..
AqlUserFunctions.md Doc - New pages: "Starter Architecture" & "Securing Starter Deployments" + Sync from external repos (#5666) 2018-06-28 17:14:56 +02:00
CollectionAccess.md Doc - New pages: "Starter Architecture" & "Securing Starter Deployments" + Sync from external repos (#5666) 2018-06-28 17:14:56 +02:00
DatabaseManipulation.md Doc - New pages: "Starter Architecture" & "Securing Starter Deployments" + Sync from external repos (#5666) 2018-06-28 17:14:56 +02:00
FoxxServices.md Doc - Improves fetch-script. Fresh Swagger. Sync external repos (#5463) 2018-05-28 16:29:30 +02:00
GraphAccess.md Doc - New pages: "Starter Architecture" & "Securing Starter Deployments" + Sync from external repos (#5666) 2018-06-28 17:14:56 +02:00
HttpRoutes.md Doc - Improves fetch-script. Fresh Swagger. Sync external repos (#5463) 2018-05-28 16:29:30 +02:00
Queries.md Doc - New pages: "Starter Architecture" & "Securing Starter Deployments" + Sync from external repos (#5666) 2018-06-28 17:14:56 +02:00
README.md Doc - sync from external repos (#5889) 2018-07-16 18:59:44 +02:00
Transactions.md Doc - New pages: "Starter Architecture" & "Securing Starter Deployments" + Sync from external repos (#5666) 2018-06-28 17:14:56 +02:00

README.md

Database API

new Database

new Database([config]): Database

Creates a new Database instance.

If config is a string, it will be interpreted as config.url.

Arguments

  • config: Object (optional)

    An object with the following properties:

    • url: string | Array<string> (Default: http://localhost:8529)

      Base URL of the ArangoDB server or list of server URLs.

      Note: As of arangojs 6.0.0 it is no longer possible to pass the username or password from the URL.

      If you want to use ArangoDB with authentication, see useBasicAuth or useBearerAuth methods.

      If you need to support self-signed HTTPS certificates, you may have to add your certificates to the agentOptions, e.g.:

      agentOptions: {
        ca: [
          fs.readFileSync(".ssl/sub.class1.server.ca.pem"),
          fs.readFileSync(".ssl/ca.pem")
        ];
      }
      
    • isAbsolute: boolean (Default: false)

      If this option is explicitly set to true, the url will be treated as the absolute database path. This is an escape hatch to allow using arangojs with database APIs exposed with a reverse proxy and makes it impossible to switch databases with useDatabase or using acquireHostList.

    • arangoVersion: number (Default: 30000)

      Value of the x-arango-version header. This should match the lowest version of ArangoDB you expect to be using. The format is defined as XYYZZ where X is the major version, Y is the two-digit minor version and Z is the two-digit bugfix version.

      Example: 30102 corresponds to version 3.1.2 of ArangoDB.

      Note: The driver will behave differently when using different major versions of ArangoDB to compensate for API changes. Some functions are not available on every major version of ArangoDB as indicated in their descriptions below (e.g. collection.first, collection.bulkUpdate).

    • headers: Object (optional)

      An object with additional headers to send with every request.

      Header names should always be lowercase. If an "authorization" header is provided, it will be overridden when using useBasicAuth or useBearerAuth.

    • agent: Agent (optional)

      An http Agent instance to use for connections.

      By default a new http.Agent (or https.Agent) instance will be created using the agentOptions.

      This option has no effect when using the browser version of arangojs.

    • agentOptions: Object (Default: see below)

      An object with options for the agent. This will be ignored if agent is also provided.

      Default: {maxSockets: 3, keepAlive: true, keepAliveMsecs: 1000}. Browser default: {maxSockets: 3, keepAlive: false};

      The option maxSockets can also be used to limit how many requests arangojs will perform concurrently. The maximum number of requests is equal to maxSockets * 2 with keepAlive: true or equal to maxSockets with keepAlive: false.

      In the browser version of arangojs this option can be used to pass additional options to the underlying calls of the xhr module.

    • loadBalancingStrategy: string (Default: "NONE")

      Determines the behavior when multiple URLs are provided:

      • NONE: No load balancing. All requests will be handled by the first URL in the list until a network error is encountered. On network error, arangojs will advance to using the next URL in the list.

      • ONE_RANDOM: Randomly picks one URL from the list initially, then behaves like NONE.

      • ROUND_ROBIN: Every sequential request uses the next URL in the list.

database.close

database.close(): void

Closes all active connections of the database instance. Can be used to clean up idling connections during longer periods of inactivity.

Note: This method currently has no effect in the browser version of arangojs.

Examples

const db = new Database();
const sessions = db.collection("sessions");
// Clean up expired sessions once per hour
setInterval(async () => {
  await db.query(aql`
    FOR session IN ${sessions}
    FILTER session.expires < DATE_NOW()
    REMOVE session IN ${sessions}
  `);
  // Make sure to close the connections because they're no longer used
  db.close();
}, 1000 * 60 * 60);