简体   繁体   English

ArangoDB中的边缘定义

[英]Edge Definition in ArangoDB

I have imported the csv files to arangodb, which are virtualmachine and server. 我已将csv文件导入到虚拟机和服务器的arangodb。 Now, I would like to create the graph to show the relationship of virtualmachine and server. 现在,我想创建一个图形来显示虚拟机和服务器的关系。

I read the manual and try to define the Edge to correlate both collections. 我阅读了手册,并尝试定义Edge以关联两个集合。 However I am not clear about how to define the edge. 但是我不清楚如何定义边缘。 (ie I need to correlate the name of server with virtualhost of virtualmachine) (即我需要将服务器的名称与虚拟机的虚拟主机相关联)

Edge Manual 边缘手册

arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" }); arangosh> myGraph.v1 = db.vertex.insert({name:“ vertex 1”});

arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" }); arangosh> myGraph.v2 = db.vertex.insert({name:“ vertex 2”});

arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2, ........> { label : "knows"}); arangosh> myGraph.e1 = db.relation.insert(myGraph.v1,myGraph.v2,........> {label:“ knows”});

In this example, how to define myGraph? 在此示例中,如何定义myGraph?

JavaScript exception: ReferenceError: myGraph is not defined
!myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
!^
stacktrace: ReferenceError: myGraph is not defined
    at <shell command>:1:1

Also, I should define the attribute of collection one by one? 另外,我应该一一定义集合的属性吗? myGraph.v1 = db.server.insert({ name : "server" }); myGraph.v1 = db.server.insert({name:“ server”}); myGraph.v2 = db.virtualmachine.insert({ name : "virtualhost" }); myGraph.v2 = db.virtualmachine.insert({name:“ virtualhost”});

Thanks for your help. 谢谢你的帮助。

to first answer the question about the example: There is one line missing in the example which defines the myGraph variable. 首先回答有关示例的问题:示例中缺少定义myGraph变量的一行。 It is hidden by accident and will be visible in the next documentation build. 它是偶然被隐藏的,在下一个文档版本中将可见。

The line which is missing is: 缺少的行是:

arangosh> var myGraph = {};

This creates an empty myGraph object. 这将创建一个空的myGraph对象。 This object is only to hold references to the vertex documents, it is not directly related to the arangodb graph modules. 该对象仅用于保存对顶点文档的引用,与arangodb图形模块没有直接关系。

the example could also use independent variables for each line: 该示例还可以为每行使用自变量:

arangosh> var v1 = db.vertex.insert({name: "vertex 1"});
arangosh> var v2 = db.vertex.insert({name: "vertex 2"});
arangosh> var e = db.relations.insert(v1, v2, {label: "knows"});

this and the above are identical on the database side. 这个和上面在数据库方面是相同的。

But now let me point you in a better direction on how to use graphs. 但是,现在让我向您指出如何使用图形的更好方向。 I think it is best if you would check the manual chapter about graphs https://docs.arangodb.com/3.1/Manual/Graphs/index.html for further information. 我认为最好查看有关图形的手册章节https://docs.arangodb.com/3.1/Manual/Graphs/index.html以获得更多信息。

arangosh> var myGraph = {};

arangosh> var myGraph.v1 = db.vertex.insert({name: "vertex 1"});
arangosh> var myGraph.v2 = db.vertex.insert({name: "vertex 2"});
arangosh> var myGraph.e = db.relations.insert(
                         myGraph.v1, myGraph.v2, {label: "knows"});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM