GraphVertexCollection API

The GraphVertexCollection API extends the Collection API with the following methods.

graphVertexCollection.remove

async graphVertexCollection.remove(documentHandle): Object

Deletes the vertex with the given documentHandle from the collection.

Arguments

  • documentHandle: string

    The handle of the vertex to retrieve. This can be either the _id or the _key of a vertex in the collection, or a vertex (i.e. an object with an _id or _key property).

Examples

const graph = db.graph("some-graph");
const collection = graph.vertexCollection("vertices");

await collection.remove("some-key");
// document 'vertices/some-key' no longer exists

// -- or --

await collection.remove("vertices/some-key");
// document 'vertices/some-key' no longer exists

graphVertexCollection.documentExists

async graphVertexCollection.documentExists(documentHandle): boolean

Checks whether the vertex with the given documentHandle exists.

Arguments

  • documentHandle: string

    The handle of the vertex to retrieve. This can be either the _id or the _key of a vertex in the collection, or a vertex (i.e. an object with an _id or _key property).

Examples

const graph = db.graph("some-graph");
const collection = graph.vertexCollection("vertices");

const exists = await collection.documentExists("some-key");
if (exists === false) {
  // the vertex does not exist
}

graphVertexCollection.document

async graphVertexCollection.document(documentHandle, [graceful]): Object

Alias: graphVertexCollection.vertex.

Retrieves the vertex with the given documentHandle from the collection.

Arguments

  • documentHandle: string

    The handle of the vertex to retrieve. This can be either the _id or the _key of a vertex in the collection, or a vertex (i.e. an object with an _id or _key property).

  • opts: Object (optional)

    If opts is set, it must be an object with any of the following properties:

    • graceful: boolean (Default: false)

      If set to true, the method will return null instead of throwing an error if the vertex does not exist.

    • allowDirtyRead: boolean (Default: false)

      Dirty reads were introduced in ArangoDB 3.4 and are not supported by earlier versions of ArangoDB.

      If set to true, the request will explicitly permit ArangoDB to return a potentially dirty or stale result and arangojs will load balance the request without distinguishing between leaders and followers.

If a boolean is passed instead of an options object, it will be interpreted as the graceful option.

Examples

const graph = db.graph("some-graph");
const collection = graph.vertexCollection("vertices");

const doc = await collection.document("some-key");
// the vertex exists
assert.equal(doc._key, "some-key");
assert.equal(doc._id, "vertices/some-key");

// -- or --

const doc = await collection.document("vertices/some-key");
// the vertex exists
assert.equal(doc._key, "some-key");
assert.equal(doc._id, "vertices/some-key");

// -- or --

const doc = await collection.vertex("some-key", true);
if (doc === null) {
  // the vertex does not exist
}

graphVertexCollection.save

async graphVertexCollection.save(data): Object

Creates a new vertex with the given data.

Arguments

  • data: Object

    The data of the vertex.

Examples

const db = new Database();
const graph = db.graph("some-graph");
const collection = graph.vertexCollection("vertices");
const doc = await collection.save({ some: "data" });
assert.equal(doc._id, "vertices/" + doc._key);
assert.equal(doc.some, "data");