要将插入到集合中的边显示在ArangoDB图中,您可以执行以下步骤:
首先,确保您已经创建了一个图集合。您可以使用以下代码示例创建一个图集合:
const arangojs = require("arangojs");
const db = new arangojs.Database();
db.useBasicAuth("username", "password");
const graph = db.graph("myGraph");
// 创建图集合
graph.create({
edgeDefinitions: [
{
collection: "myCollection",
from: ["myVertexCollection"],
to: ["myVertexCollection"]
}
]
})
.then(() => console.log("Graph collection created"))
.catch(err => console.error("Failed to create graph collection:", err));
然后,您可以使用以下代码示例将边插入到集合中并在图中显示:
const arangojs = require("arangojs");
const db = new arangojs.Database();
db.useBasicAuth("username", "password");
const collection = db.collection("myCollection");
// 插入边到集合中
collection.save({ _from: "myVertexCollection/vertex1", _to: "myVertexCollection/vertex2" })
.then(() => console.log("Edge inserted into collection"))
.catch(err => console.error("Failed to insert edge into collection:", err));
// 更新图
collection.graph("myGraph")
.then(() => console.log("Graph updated"))
.catch(err => console.error("Failed to update graph:", err));
通过将边插入到集合中并使用graph()
方法将其与图相关联,边将在图中显示。请确保将上述代码示例中的"myGraph"
、"myCollection"
、"myVertexCollection"
以及"vertex1"
和"vertex2"
替换为您自己的集合和顶点信息。
请注意,这里的代码示例使用了arangojs库来与ArangoDB进行交互。您需要先安装arangojs库,然后再将其与您的项目一起使用。