0
votes

I have imported the csv files to arangodb, which are virtualmachine and server. 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. However I am not clear about how to define the edge. (i.e. 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.v2 = db.vertex.insert({ name : "vertex 2" });

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

In this example, how to define 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.v2 = db.virtualmachine.insert({ name : "virtualhost" });

Thanks for your help.

2

2 Answers

1
votes

to first answer the question about the example: There is one line missing in the example which defines the myGraph variable. 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. This object is only to hold references to the vertex documents, it is not directly related to the arangodb graph modules.

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.

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