Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GraphEdgeCollection<T>

Represents a EdgeCollection of edges in a Graph.

Type parameters

  • T: Record<string, unknown> = any

    Type to use for document data. Defaults to any.

Hierarchy

  • GraphEdgeCollection

Implements

Index

Accessors

collection

graph

  • The Graph instance this edge collection is bound to.

    Returns Graph

isArangoCollection

  • get isArangoCollection(): true

name

  • get name(): string

Methods

edge

  • 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.

    example
    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    try {
      const edge = await collection.edge("abc123");
      console.log(edge);
    } catch (e) {
      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");
    }
    

    Parameters

    Returns Promise<Edge<T>>

  • 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.

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

    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>>

edgeExists

  • 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.

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

    Parameters

    • selector: DocumentSelector

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

    Returns Promise<boolean>

remove

  • Removes an existing edge from the collection.

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

    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
    

    Parameters

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

replace

  • Replaces an existing edge in the collection.

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

    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
    

    Parameters

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

save

  • Inserts a new edge with the given data into the collection.

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

    Parameters

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

update

  • Updates an existing edge in the collection.

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

    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
    

    Parameters

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

Generated using TypeDoc