Class GraphEdgeCollection<T>

Represents a collection.EdgeCollection of edges in a graph.Graph.

Type Parameters

  • T extends Record<string, any> = any

    Type to use for document data. Defaults to any.

Implements

Accessors

  • get graph(): Graph
  • The graph.Graph instance this edge collection is bound to.

    Returns Graph

  • get name(): string
  • Name of the collection.

    Returns string

Methods

  • Retrieves the edge matching the given key or id.

    Throws an exception when passed a edge or _id from a different collection, or if the edge does not exist.

    Parameters

    Returns Promise<Edge<T>>

    Example

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

    Example

    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    const edge = await collection.edge("abc123", { graceful: true });
    if (edge) {
    console.log(edge);
    } else {
    console.error("Edge does not exist");
    }
  • Retrieves the edge matching the given key or id.

    Throws an exception when passed a edge or _id from a different collection, or if the edge does not exist.

    Parameters

    • selector: DocumentSelector

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

    • graceful: boolean

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

    Returns Promise<Edge<T>>

    Example

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

    Example

    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    const edge = await collection.edge("abc123", true);
    if (edge) {
    console.log(edge);
    } else {
    console.error("Edge does not exist");
    }
  • Checks whether a edge matching the given key or id exists in this collection.

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

    Parameters

    • selector: DocumentSelector

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

    Returns Promise<boolean>

    Example

    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    const exists = await collection.edgeExists("abc123");
    if (!exists) {
    console.log("Edge does not exist");
    }
  • Removes an existing edge from the collection.

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

    Parameters

    Returns Promise<DocumentMetadata & {
        old?: Edge<T>;
    }>

    Example

    const db = new Database();
    const collection = db.collection("friends");
    const doc = await collection.edge("musadir");
    await collection.remove(doc);
    // edge with key "musadir" deleted
  • Replaces an existing edge in the collection.

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

    Parameters

    Returns Promise<DocumentMetadata & {
        new?: Edge<T>;
        old?: Edge<T>;
    }>

    Example

    const db = new Database();
    const collection = db.collection("friends");
    await collection.save(
    {
    _key: "musadir",
    _from: "users/rana",
    _to: "users/mudasir",
    active: true,
    best: true
    }
    );
    const result = await collection.replace(
    "musadir",
    { active: false },
    { returnNew: true }
    );
    console.log(result.new.active, result.new.best); // false undefined
  • Inserts a new edge with the given data into the collection.

    Parameters

    Returns Promise<DocumentMetadata & {
        new?: Edge<T>;
    }>

    Example

    const db = new Database();
    const collection = db.collection("friends");
    const result = await collection.save(
    { _from: "users/rana", _to: "users/mudasir", active: false },
    { returnNew: true }
    );
  • Updates an existing edge in the collection.

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

    Parameters

    Returns Promise<DocumentMetadata & {
        new?: Edge<T>;
        old?: Edge<T>;
    }>

    Example

    const db = new Database();
    const collection = db.collection("friends");
    await collection.save(
    {
    _key: "musadir",
    _from: "users/rana",
    _to: "users/mudasir",
    active: true,
    best: true
    }
    );
    const result = await collection.update(
    "musadir",
    { active: false },
    { returnNew: true }
    );
    console.log(result.new.active, result.new.best); // false true