A collection.EdgeCollection instance for this edge collection.
The graph.Graph instance this edge collection is bound to.
Name of the collection.
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.
Document _key
, _id
or object with either of those
properties (e.g. a edge from this collection).
Optional
options: GraphCollectionReadOptionsOptions for retrieving the edge.
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");
}
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.
Document _key
, _id
or object with either of those
properties (e.g. a edge from this collection).
If set to true
, null
is returned instead of an
exception being thrown if the edge does not exist.
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");
}
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.
Document _key
, _id
or object with either of those
properties (e.g. a edge from this collection).
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.
Document _key
, _id
or object with either of those
properties (e.g. a edge from this collection).
Optional
options: GraphCollectionRemoveOptionsOptions for removing the edge.
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.
Document _key
, _id
or object with either of those
properties (e.g. a edge from this collection).
Optional
options: GraphCollectionReplaceOptionsOptions for replacing the edge.
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.
The contents of the new edge.
Optional
options: GraphCollectionInsertOptionsOptions for inserting the edge.
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.
Document _key
, _id
or object with either of those
properties (e.g. a edge from this collection).
Optional
options: GraphCollectionReplaceOptionsOptions for updating the edge.
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
Represents a collection.EdgeCollection of edges in a graph.Graph.