ArangoDB database setup for a beginner

Mrinal Barua
3 min readFeb 5, 2019

--

ArangoDB is found as a multi-model No-SQL database system which supports JSON, Graph & Key-Value data-set in it’s storage engine. Compare to other multiple-model database system it’s pretty simple and straightforward.

For it’s feature details you can visit https://www.arangodb.com.

Sharing a simple data-structure here with sample data set which I gone through. Let’s consider the hierarchical structure of an organisation where there are multiple CXOs associated with different department having some employees in each department. My example considers the sample data to form following graph structure:

Figure 1: Visual Graph using ArangoDB

Above figure represents that there are three CXOs associated to your organisation(org) as CTO, CPO & CBO. Each of them is associated with their own departments having department wise employees.

Hands on Practice:

Install ArangoDB from as instructed in https://www.arangodb.com/download-major/ubuntu/

Login to ArangoDB Shell using command arangosh providing your root password used during installation.

Figure 2: Login to ArangoDB shell

Create a database

Figure 3: Create a new database

Use Database

Figure 4: Use newly created database

Create collections:

> db._create(“org”);
> db._create(“cxo”);
> db._create(“department”);
> db._create(“employee”);

Create relations:

> db._createEdgeCollection(“org_cxo”);
> db._createEdgeCollection(“cxo_dept”);
> db._createEdgeCollection(“dept_emp”);

Create Organisation data[root node]:

> db.org.save({ _key: “org”, name: “My Organisation Name”});

Create cxo data:

> db.cxo.save({ _key: “ceo”, name: “Chief Executive Officer”});
> db.cxo.save({ _key: “cto”, name: “Chief Technical Officer” });
> db.cxo.save({ _key: “cbo”, name: “Chief Business Officer” });
> db.cxo.save({ _key: “cpo”, name: “Chief Product Officer” });

Create Dept data:

> db.department.save({ _key: “technical”, name: “Technology”})
> db.department.save({ _key: “business”, name: “Business”})
> db.department.save({ _key: “product”, name: “Product”})

Create Employee data:

> db.employee.save({ _key: “john”, name: “John Marshel”, DOJ: “01–01–2000” })
> db.employee.save({ _key: “tonny”, name: “Tonny Jha”, DOJ: “01–02–2000” })
> db.employee.save({ _key: “iron”, name: “Iron Man”, DOJ: “01–03–2000” })
> db.employee.save({ _key: “shaktiman”, name: “Shakti Man”, DOJ: “01–03–2000” })
> db.employee.save({ _key: “hulk”, name: “Hulk”, DOJ: “01–04–2000” })
> db.employee.save({ _key: “thor”, name: “Thor”, DOJ: “01–04–2000” })

Establish Org/CXO relation:

> db.org_cxo.save(“org/org”, “cxo/ceo”, { Founder: ‘Yes’ });
> db.org_cxo.save(“org/org”, “cxo/cto”, { Founder: ‘No’ });
> db.org_cxo.save(“org/org”, “cxo/cbo”, { Founder: ‘No’ });
> db.org_cxo.save(“org/org”, “cxo/cpo”, { Founder: ‘Yes’ });

Establish CXO/Dept relation:

> db.cxo_dept.save(“cxo/ceo”, “department/technical”, { ownership: ‘partial’ });
> db.cxo_dept.save(“cxo/ceo”, “department/business”, { ownership: ‘partial’ });
> db.cxo_dept.save(“cxo/ceo”, “department/product”, { ownership: ‘partial’ });
> db.cxo_dept.save("cxo/cto", "department/technical", { ownership: 'full' });
> db.cxo_dept.save("cxo/cbo", "department/business", { ownership: 'full' });
> db.cxo_dept.save("cxo/cpo", "department/product", { ownership: 'full' });

Establish Dept/Employee:

> db.dept_emp.save(“department/technical”, “employee/john”, { type: ‘full time’ });
> db.dept_emp.save("department/technical", "employee/tonny", { type: 'full time' });
> db.dept_emp.save("department/business", "employee/iron", { type: 'full time' });
> db.dept_emp.save("department/business", "employee/shaktiman", { type: 'full time' });
> db.dept_emp.save("department/product", "employee/hulk", { type: 'full time' });
> db.dept_emp.save("department/product", "employee/thor", { type: 'full time' });

Now your data & relation everything is ready. It’s time to create a visual graph. Follow below steps to create a graph.

Login to http://localhost:8529/_db/my_organization/_admin/aardvark/index.html & click on Graph -> Add Graph

Figure 5: Create a Visual Graph

Create a graph by provide following relational details with three sections in above UI.

Edge 1:

Edge definitions*: org_cxo
fromCollections*: org
toCollections*: cxo

Edge 2:

Edge definitions*: cxo_dept
fromCollections*: cxo
toCollections*: department

Edge 3:

Edge definitions*: dept_emp
fromCollections*: department
toCollections*: employee

Now you open your graph and expand all nodes to get complete relations. Hope you enjoyed the example.

Reference URL: https://www.arangodb.com/

--

--