Class GraphVertexCollection<EntryResultType, EntryInputType>

Represents a collections.DocumentCollection of vertices in a Graph.

Type Parameters

  • EntryResultType extends Record<string, any> = any

    Type to represent vertex document contents returned by the server (including computed properties).

  • EntryInputType extends Record<string, any> = EntryResultType

    Type to represent vertex document contents passed when inserting or replacing vertex documents (without computed properties).

Implements

Accessors

Methods

  • Removes an existing vertex from the collection.

    Throws an exception when passed a vertex or _id from a different collection.

    Parameters

    Returns Promise<DocumentMetadata & {
        old?: Document<EntryResultType>;
    }>

    Example

    const graph = db.graph("some-graph");
    const collection = graph.vertexCollection("vertices");
    await collection.remove("abc123");
    // document with key "abc123" deleted

    Example

    const graph = db.graph("some-graph");
    const collection = graph.vertexCollection("vertices");
    const doc = await collection.vertex("abc123");
    await collection.remove(doc);
    // document with key "abc123" deleted
  • Retrieves the vertex matching the given key or id.

    Throws an exception when passed a vertex or _id from a different collection.

    Parameters

    • selector: DocumentSelector

      Document _key, _id or object with either of those properties (e.g. a vertex from this collection).

    • Optional options: ReadGraphDocumentOptions

      Options for retrieving the vertex.

    Returns Promise<Document<EntryResultType>>

    Example

    const graph = db.graph("some-graph");
    const collection = graph.vertexCollection("vertices");
    try {
    const vertex = await collection.vertex("abc123");
    console.log(vertex);
    } catch (e: any) {
    console.error("Could not find vertex");
    }

    Example

    const graph = db.graph("some-graph");
    const collection = graph.vertexCollection("vertices");
    const vertex = await collection.vertex("abc123", { graceful: true });
    if (vertex) {
    console.log(vertex);
    } else {
    console.error("Could not find vertex");
    }
  • Retrieves the vertex matching the given key or id.

    Throws an exception when passed a vertex or _id from a different collection.

    Parameters

    • selector: DocumentSelector

      Document _key, _id or object with either of those properties (e.g. a vertex from this collection).

    • graceful: boolean

      If set to true, null is returned instead of an exception being thrown if the vertex does not exist.

    Returns Promise<Document<EntryResultType>>

    Example

    const graph = db.graph("some-graph");
    const collection = graph.vertexCollection("vertices");
    try {
    const vertex = await collection.vertex("abc123", false);
    console.log(vertex);
    } catch (e: any) {
    console.error("Could not find vertex");
    }

    Example

    const graph = db.graph("some-graph");
    const collection = graph.vertexCollection("vertices");
    const vertex = await collection.vertex("abc123", true);
    if (vertex) {
    console.log(vertex);
    } else {
    console.error("Could not find vertex");
    }
  • Checks whether a vertex matching the given key or id exists in this collection.

    Throws an exception when passed a vertex or _id from a different collection.

    Parameters

    • selector: DocumentSelector

      Document _key, _id or object with either of those properties (e.g. a vertex from this collection).

    Returns Promise<boolean>

    Example

    const graph = db.graph("some-graph");
    const collection = graph.vertexCollection("vertices");
    const exists = await collection.vertexExists("abc123");
    if (!exists) {
    console.log("Vertex does not exist");
    }