Skip to the content.

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

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

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

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

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");