5

I am trying to execute following JS file using arangosh in order to build my graph. The file executes without error but when I go into web interface, I do see a graph created but no vertices or edges in the graph.

db._dropDatabase("database");

db. _createDatabase("database", [], [{username: "admin", passwd: "admin", active: true}]);
db._useDatabase("database");

var graph_module =  require("org/arangodb/general-graph");
var graph = graph_module._create("myGraph");

//Add top level documents
graph._addVertexCollection("users");
graph._addVertexCollection("positions");

graph._extendEdgeDefinitions(graph_module._relation("has_worked_at", ["users"], ["positions"]));

I save this file as database.js and then run following command

arangosh --javascript.execute database.js

1 Answer 1

3

The graph was created, the two vertex collections and the edge collection as well, but they do not contain any documents (vertices and edges). If you add

db.users.insert({_key:"Max"});
db.positions.insert({_key:"ArangoDB"});
db.has_worked_at.insert("users/Max", "positions/ArangoDB", {developer:true});

to your script, you will see two vertices and an edge in the graph viewer.

Sign up to request clarification or add additional context in comments.

1 Comment

Also works by using the collections via the graph module: var user1 = graph.users.insert({_key: "user1", name: "John Doe"}); var user2 = graph.users.insert({_key: "user2", name: "Jane Smith"}); var pos1 = graph.positions.insert({name: "junior manager"}); var pos2 = graph.positions.insert({name: "senior manager"}); var pos3 = graph.positions.insert({name: "developer"}); graph.has_worked_at.insert(user1._id, pos1._id, {company: "ACME corp."}); graph.has_worked_at.insert(user1._id, pos2._id, {company: "Sample inc."}); graph.has_worked_at.insert(user2._id, pos2._id, {company: "Foobar LLC"});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.