Sunday, July 24, 2016

How To Install & Use ArangoDB 3 On Ubuntu 14.04 and 16.04 LTS

How To Install & Use ArangoDB 3
On
Ubuntu 14.04 and 16.04 LTS

ArangoDB is a NoSQL, multi-model, open-source database with flexible data models for documents, graphs, and key-values. Build high performance applications using a convenient SQL-like query language or JavaScript extensions. Its creators refer to it as a "native multi-model" database to indicate that it was designed specifically to allow key/value, document, and graph data to be stored together and queried with a common language (known as AQL).
ArangoDB On GitHub.

Significant Features Of ArangoDB

  • Multi-Model : Documents, graphs and key-value pairs - model your data as you see fit for your application.
  • Joins : Conveniently join what belongs together for flexible ad-hoc querying, less data redundancy.
  • Transactions : Easy application development keeping your data consistent and safe. No hassle in your client.
  • It is open source (Apache License 2.0)
  • ArangoDB is multi-threaded - exploit the power of all your cores

Install ArangoDB :

Method 1:

In this method you have to execute commands shown below one by one(manually) to install ArangoDB.. but method 2 is more easy way to do this... because the second method uses shell script that will do all these installation steps automatically, for you.. .


Step 1 : First add the repository key to apt :

For Ubuntu 16.04 LTS :

wget https://www.arangodb.com/repositories/arangodb3/xUbuntu_16.04/Release.key && sudo apt-key add - < Release.key

For Ubuntu 14.04 LTS :

wget https://www.arangodb.com/repositories/arangodb3/xUbuntu_14.04/Release.key && sudo apt-key add - < Release.key The sample output should be like this..
shivaraj@shivaraj-A14RM0E:~$ wget https://www.arangodb.com/repositories/arangodb3/xUbuntu_14.04/Release.key && sudo apt-key add - < Release.key --2016-07-21 20:29:00-- https://www.arangodb.com/repositories/arangodb3/xUbuntu_14.04/Release.key Resolving www.arangodb.com (www.arangodb.com)... 85.214.140.94 Connecting to www.arangodb.com (www.arangodb.com)|85.214.140.94|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1003 [application/pgp-keys] Saving to: ‘Release.key’ 100%[=============================================================================================================>] 1,003 --.-K/s in 0s 2016-07-21 20:29:01 (9.99 MB/s) - ‘Release.key’ saved [1003/1003] [sudo] password for shivaraj: OK shivaraj@shivaraj-A14RM0E:~$

Step 2 : Create a list file for ArangoDB & Update The Source List

Next, you need to add the ArangoDB repository details so apt will know where to download the packages from... After adding the repository details, you will need to update the packages list.

For Ubuntu 16.04 LTS :

echo 'deb https://www.arangodb.com/repositories/arangodb3/xUbuntu_16.04/ /' | sudo tee /etc/apt/sources.list.d/arangodb.list && sudo apt-get update

For Ubuntu 14.04 LTS :

echo 'deb https://www.arangodb.com/repositories/arangodb3/xUbuntu_14.04/ /' | sudo tee /etc/apt/sources.list.d/arangodb.list && sudo apt-get update

Step 3 : Install the ArangoDB packages

You can install the latest stable release of ArangoDB version 3 with following command...

sudo apt-get install arangodb3

The above command will install ArangoDB from official ArangoDB repos... contains following packages..

The ArangoDB package comes with the following programs:

  • arangod: The ArangoDB database daemon. This server program is intended to run as a daemon process and to serve the various clients connection to the server via TCP / HTTP.

  • arangosh: The ArangoDB shell. A client that implements a read-eval-print loop (REPL) and provides functions to access and administrate the ArangoDB server.

  • arangoimp: A bulk importer for the ArangoDB server. It supports JSON and CSV.

  • arangodump: A tool to create backups of an ArangoDB database in JSON format.

  • arangorestore: A tool to load data of a backup back into an ArangoDB database.

  • arango-dfdb: A datafile debugger for ArangoDB. It is primarily intended to be used during development of ArangoDB.

  • arangobench: A benchmark and test tool. It can be used for performance and server function testing.

Step 4 :See The Status Of ArangoDB

Issue the following command to check the status of arangod (arangodb server)

For Ubuntu 14.04 :

sudo service arangodb3 status

If ArangoDB Running properly, you should get output like this..

shivaraj@shivaraj-A14RM0E:~$ sudo service arangodb3 status * arangod is running shivaraj@shivaraj-A14RM0E:~$

For Ubuntu 16.04 :

sudo systemctl status arangodb3

The above command will produce following output if ArangoDB works fine..

shivaraj@shivaraj-A14RM0E:~$ sudo systemctl status arangodb3 arangodb3.service - LSB: arangodb Loaded: loaded (/etc/init.d/arangodb3; bad; vendor preset: enabled) Active: active (running) since Sat 2016-07-23 17:52:15 IST; 1min 2s ago Docs: man:systemd-sysv-generator(8) CGroup: /system.slice/arangodb3.service ├─4857 /usr/sbin/arangod --uid arangodb --gid arangodb --pid-file /var/run/arangodb/arangod.pid --temp.path /var/tmp/arangod --log.fo └─4858 /usr/sbin/arangod --uid arangodb --gid arangodb --pid-file /var/run/arangodb/arangod.pid --temp.path /var/tmp/arangod --log.fo Jul 23 17:52:10 shivaraj-A14RM0E systemd[1]: Starting LSB: arangodb... Jul 23 17:52:11 shivaraj-A14RM0E arangodb3[4801]: * Starting arango database server arangod Jul 23 17:52:15 shivaraj-A14RM0E arangodb3[4801]: {startup} starting up in daemon mode Jul 23 17:52:15 shivaraj-A14RM0E arangodb3[4801]: changed working directory for child process to '/var/tmp' Jul 23 17:52:15 shivaraj-A14RM0E arangodb3[4801]: ...done. Jul 23 17:52:15 shivaraj-A14RM0E systemd[1]: Started LSB: arangodb.

Securing the installation :

The default installation contains one database _system and a user named root . Debian based packages and the Windows installer will ask for a password during the installation process. Red-Hat based packages will set a random password. For all other installation packages you need to execute.
arango-secure-installation This will asked you for a root password and sets this password.

Method 2:

In this method, the following command will download shell script from GitHub repo and will execute it to make installation of ArangoDB easy.. The downloaded script will take care of all things..

wget -O - https://raw.githubusercontent.com/shivarajnaidu/UV-Shell-Scripts/master/ArangoDB%20Installation%20Scripts/arangodb-installation-script-for-ubuntu.sh | bash -

Basic Use Of ArangoDB (On Ubuntu)..

You can interact with ArangoDB server in two ways.. One way is ArangoDB shell (arangosh) - A command line interface to interact with ArangoDB server... Another way is ArangoDB web interface which offers GUI interface to interact with ArangoDB server..

Accessing ArangoDB from shell (arangosh) :

Run the arangosh command to invoke ArangoDB Shell:

The ArangoDB shell (arangosh) is a command-line tool that can be used for administration of ArangoDB, including running ad-hoc queries. It offers a JavaScript shell environment providing access to the ArangoDB server. Arangosh can be invoked like this:

arangosh
If the above command asks you for password after its execution starts... type a password if you have set one while installing ArangoDB on your system..
If you didn't set any password while installing ArangoDB then the password is empty.. You can proceed just by leaving it as empty while it asking for password.. Just hit ENTER key..

If Arangosh started successfully You will see output like the one shown below..

shivaraj@shivaraj-A14RM0E:~$ arangosh Please specify a password: arangosh (ArangoDB 3.0.3 [linux] 64bit, using VPack 0.1.30, ICU 54.1, V8 5.0.71.39, OpenSSL 1.0.1f 6 Jan 2014) Copyright (c) ArangoDB GmbH Pretty printing values. Connected to ArangoDB 'http+tcp://127.0.0.1:8529' version: 3.0.3 [server], database: '_system', username: 'root' Type 'tutorial' for a tutorial or 'help' to see common examples 127.0.0.1:8529@_system>

We can get more detailed help for command line administration of ArangoDB by running help command.

Run help command in arangodb shell, output will look like this..

127.0.0.1:8529@_system> help ------------------------------------- Help ------------------------------------- Predefined objects: arango: ArangoConnection db: ArangoDatabase fm: FoxxManager Examples: > db._collections() list all collections > db._query(<query>).toArray() execute an AQL query > db._explain(<query>) explain an AQL query > help show help pages > exit Note: collection names and statuses may be cached in arangosh. To refresh the list of collections and their statuses, issue: > db._collections(); To cancel the current prompt, press CTRL + d. --------------------------- ArangoDatabase (db) help --------------------------- Administration Functions: _help() this help _flushCache() flush and refill collection cache Collection Functions: _collections() list all collections _collection(<name>) get collection by identifier/name _create(<name>, <properties>) creates a new collection _createEdgeCollection(<name>) creates a new edge collection _drop(<name>) delete a collection Document Functions: _document(<id>) get document by handle (_id) _replace(<id>, <data>, <overwrite>) overwrite document _update(<id>, <data>, <overwrite>, partially update document <keepNull>) _remove(<id>) delete document _exists(<id>) checks whether a document exists _truncate() delete all documents Database Management Functions: _createDatabase(<name>) creates a new database _dropDatabase(<name>) drops an existing database _useDatabase(<name>) switches into an existing database _drop(<name>) delete a collection _name() name of the current database Query / Transaction Functions: _executeTransaction(<transaction>) execute transaction _query(<query>) execute AQL query _createStatement(<data>) create and return AQL query ----------------------------- ArangoCollection help ----------------------------- ArangoCollection constructor: > col = db.mycoll; > col = db._create("mycoll"); Administration Functions: name() collection name status() status of the collection type() type of the collection truncate() delete all documents properties() show collection properties drop() delete a collection load() load a collection unload() unload a collection rename(<new-name>) renames a collection getIndexes() return defined indexes refresh() refreshes the status and name _help() this help Document Functions: count() return number of documents save(<data>) create document and return handle document(<id>) get document by handle (_id or _key) replace(<id>, <data>, <overwrite>) overwrite document update(<id>, <data>, <overwrite>, partially update document <keepNull>) remove(<id>) delete document exists(<id>) checks whether a document exists Attributes: _database database object _id collection identifier ----------------------------- ArangoStatement help ----------------------------- Create an AQL query: > stmt = new ArangoStatement(db, { "query": "FOR..." }) > stmt = db._createStatement({ "query": "FOR..." }) Set query options: > stmt.setBatchSize(<value>) set the max. number of results to be transferred per roundtrip > stmt.setCount(<value>) set count flag (return number of results in "count" attribute) Get query options: > stmt.setBatchSize() return the max. number of results to be transferred per roundtrip > stmt.getCount() return count flag (return number of results in "count" attribute) > stmt.getQuery() return query string results in "count" attribute) Bind parameters to a query: > stmt.bind(<key>, <value>) bind single variable > stmt.bind(<values>) bind multiple variables Execute query: > cursor = stmt.execute() returns a cursor Get all results in an array: > docs = cursor.toArray() Or loop over the result set: > while (cursor.hasNext()) { print(cursor.next()) } ---------------------------- ArangoQueryCursor help ---------------------------- ArangoQueryCursor constructor: > cursor = stmt.execute() Functions: hasNext() returns true if there are more results to fetch next() returns the next document toArray() returns all data from the cursor _help() this help Attributes: _database database object Example: > stmt = db._createStatement({ "query": "FOR c IN coll RETURN c" }) > cursor = stmt.execute() > documents = cursor.toArray() > cursor = stmt.execute() > while (cursor.hasNext()) { print(cursor.next()) } ----------------------------------- More help ----------------------------------- Pager: > stop_pager() stop the pager output > start_pager() start the pager Pretty printing: > stop_pretty_print() stop pretty printing > start_pretty_print() start pretty printing Color output: > stop_color_print() stop color printing > start_color_print() start color printing Print function: > print(x) std. print function > print_plain(x) print without prettifying and without colors > clear() clear screen 127.0.0.1:8529@_system>

The result is basically a JavaScript shell where you can run arbitrary JavaScript code. For example, add two numbers:

127.0.0.1:8529@_system> 23 + 2

You will get output like this..

127.0.0.1:8529@_system> 23 + 2 25 127.0.0.1:8529@_system>

User Management In ArangoDB :

ArangoDB allows to restrict access to databases to certain users. All users of the system database are considered administrators. During installation a default user root is created, which has access to all databases.
You should create a database for your application together with a user that has access rights to database.

The default installation contains one database _system and a user named root.
Debian based package installer will ask for a password during the installation process. Red-Hat based packages will set a random password. For all other installation packages you need to execute.
arango-secure-installation This would ask you for a root password and sets this password.
If you leave password field as blank ... you can login without entering password..

Creating A New User :

The following would create a user named shivaraj.. (But, by default, this user will have no access at all (to any database).. we need to give privilege to newly created user, to access database.)

var users = require("@arangodb/users"); users.save("shivaraj", "mypassword");

Or

require("@arangodb/users").save("shivaraj", "mypassword");

The Output would be look like below..

127.0.0.1:8529@_system> require("@arangodb/users").save("shivaraj", "root"); { "user" : "shivaraj", "active" : true, "extra" : { }, "changePassword" : false, "code" : 201 } 127.0.0.1:8529@_system>

The save method will take 4 parameters.. like shown below..

require("@arangodb/users").save(user, password, active, extra);

This will create a new ArangoDB user. The user_name must be specified in user and must not be empty.
The password must be given as a string, too, but can be left empty if required.
If the active attribute is not specified, it defaults to true. The extra attribute can be used to save custom data with the user.

Note: This method will fail if either the username or the passwords are not specified or given in a wrong format, or there already exists a user with the specified name.
In addition to this.. the newly created user will not have permission to access any database. You need to grant the access rights for one or more databases using grantDatabase method...

Granting & Revoking Permission To User, To Access The Database :

So after creating User we need to give privilege to new user to access the database using grantDatabase method. revokeDatabase method will revoke the right to access database.

Granting permission to access Database :

The following will grants read/write access to the database for the user.

require("@arangodb/users").grantDatabase(user, database);

For Example, The following will grant permission to user named shivaraj to access database uvdb.

require("@arangodb/users").grantDatabase("shivaraj", "uvdb");
Note : If a user has access rights to the _system database, he is considered superuser.

Revoking permission to access Database :

The following will revokes read/write access to the database for the user.

require("@arangodb/users").revokeDatabase(user, database);

For Example, The following will revoke permission to user named shivaraj to access database uvdb.

require("@arangodb/users").revokeDatabase("shivaraj", "uvdb");

List All ArangoDB Users :

The following will list all users belongs to ArangoDB...

require("@arangodb/users").all();

The output would look like following one...

127.0.0.1:8529@_system> require("@arangodb/users").all(); [ { "user" : "shivaraj", "active" : true, "extra" : { }, "changePassword" : false }, { "user" : "root", "active" : true, "extra" : { }, "changePassword" : false } ] 127.0.0.1:8529@_system>

Removing A User :

The following will delete user from ArangoDB

require("@arangodb/users").remove(user);

Remove method will remove an existing ArangoDB user from the database.
The username must be specified in User and the specified user must exist in the database.
This method will fail if the user cannot be found in the database.

For example, Following will remove user named shivaraj from ArangoDB..

require("@arangodb/users").remove("shivaraj");

See More about User Management In Official ArangoDB Documentation..

Basic Database Management :

This section will explain you ... performing basic CURD operations on Databases through ArangoDB shell(arangosh)

Creating A New Database..

We can create a new database using createDatabase method..

Syntax :
db._createDatabase(name, options, users)

The createDatabase will accept 3 parameters ...

  • The first parameter(name) will specify the name of the database we are going to create

  • The second parameter(options) currently has no meaning and is reserved for future use.

  • The optional users attribute can be used to create initial users for the new database. If specified, it must be a list of user objects. Each user object can contain the following attributes:

    1. username: the user name as a string. This attribute is mandatory.

    2. passwd: the user password as a string. If not specified, then it defaults to an empty string.

    3. active: a boolean flag indicating whether the user account should be active or not. The default value is true.

    4. extra: an optional JSON object with extra user information. The data contained in extra will be stored for the user but not be interpreted further by ArangoDB.

If no initial users are specified, a default user root will be created with an empty string password. This ensures that the new database will be accessible via HTTP after it is created.

For example.. The following will create database named 'uvdb' with user named shivaraj .

db._createDatabase("uvdb", [], [{ username: "shivaraj", passwd: "root"}]);

The sample output would look like this, if database created successfully..

127.0.0.1:8529@_system> db._createDatabase("uvdb", [], [{ username: "shivaraj", passwd: "root"}]); true 127.0.0.1:8529@_system>
Note that even if the database is created successfully, there will be no change into the current database to the new database. Changing the current database must explicitly be requested by using the db._useDatabase method.

Switch to Particular Database :

You can switch to particular database from the current database using db._useDatabase method.

Syntax :
db._useDatabase(db_name);

The following will switch to newly created database uvdb from currently working database..

db._useDatabase('uvdb');

The sample output will be look like following one..

127.0.0.1:8529@_system> db._useDatabase('uvdb'); true 127.0.0.1:8529@uvdb>

List All Existing Databases In ArangoDB :

We can list all existing Databases in ArangoDB using db._databases method..

db._databases();
Sample output :
127.0.0.1:8529@_uvdb> db._databases(); [ "_system", "uvdb" ] 127.0.0.1:8529@uvdb>

Drop/Delete A Database :

We can drop(delete) an existing database using _dropDatabase method..

db._dropDatabase(name);

For example, following will delete database named "uvdb"...

db._dropDatabase('uvdb');
Sample output :
127.0.0.1:8529@_system> db._dropDatabase('uvdb'); true 127.0.0.1:8529@_system>
Note: Dropping databases is only possible from within the _system database. The _system database itself cannot be dropped.

Basic Collection Management :

This section will explain you ... performing basic CURD operations on Collections in a Database through ArangoDB shell(arangosh)

Creating A New Collection In Database:

We can create a new collection using _create method.

db._create(collection-name);

For example, The following will create collection named "myfriends"..

db._create('myfriends');
Sample output :
127.0.0.1:8529@_uvdb>db._create('myfriends'); [ArangoCollection 119334, "myfriends" (type document, status loaded)] 127.0.0.1:8529@uvdb>
Note : You can access an existing collection using _collection method..
Syntax :
db._collection(collection-name);

List All Existing Collections Of Current Database:

The _collections method will return all existing collections from current database..

db._collections();
Sample output :
127.0.0.1:8529@_uvdb> db._collections(); [ [ArangoCollection 117935, "_apps" (type document, status loaded)], [ArangoCollection 117933, "_jobs" (type document, status loaded)], [ArangoCollection 117931, "_queues" (type document, status loaded)], [ArangoCollection 117929, "_frontend" (type document, status loaded)], [ArangoCollection 119334, "myfriends" (type document, status loaded)], [ArangoCollection 117904, "_graphs" (type document, status loaded)], [ArangoCollection 117914, "_routing" (type document, status loaded)], [ArangoCollection 117912, "_modules" (type document, status loaded)], [ArangoCollection 117927, "_aqlfunctions" (type document, status loaded)] ] 127.0.0.1:8529@uvdb>

Drop/Delete A Collection :

We can drop(delete) an existing collection using _drop method..

db._drop(collection-name);

For example, following will delete collection named "myfriends"...

db._drop('myfriends');

Basic Document Management :

This section will explain you ... performing basic CURD operations on Documents in a Collection through ArangoDB shell(arangosh)

Creating A New Document In Collection:

We can create a new document using collection.insert method.

db.collection.insert(data);

The above creates a new document in the collection from the given data. The data must be an object.

Note: Since ArangoDB 2.2, insert is an alias for save.

For example the following will create new document in collection named "myfriends"..

db.myfriends.insert( { "name" : "balu", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education":"computer engineering", "occupation" : "software professional" } )
Sample output :
127.0.0.1:8529@_uvdb> db.myfriends.insert( ...> { ...> "name" : "balu", ...> "address" : { ...> "street" : "Ramar Street", ...> "village" : "Sri Rama Kuppam", ...> "post" : "seethanjeri", ...> "pincode" : "602026", ...> "taluk" : "Uthukkottai", ...> "nation" : "India" ...> }, ...> "education":"computer engineering", ...> "occupation" : "software professional" ...> } ...> ) { "_id" : "myfriends/142037", "_key" : "142037", "_rev" : "142037" } 127.0.0.1:8529@uvdb>

To Insert Multiple Documents into Collection :

To insert multiple documents into collection named myfriends .. pass an array of objects to insert method..

Syntax :
db.myfriends.insert([ { "name" : "balu", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education":"computer engineering", "occupation" : "software professional" }, { "name" : "babu", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "USA" }, "education":"computer engineering", "occupation" : "software professional" } ])
Sample output :
127.0.0.1:8529@_uvdb> db.myfriends.insert([ ...> { ...> "name" : "balu", ...> "address" : { ...> "street" : "Ramar Street", ...> "village" : "Sri Rama Kuppam", ...> "post" : "seethanjeri", ...> "pincode" : "602026", ...> "taluk" : "Uthukkottai", ...> "nation" : "India" ...> }, ...> "education":"computer engineering", ...> "occupation" : "software professional" ...> }, ...> { ...> "name" : "babu", ...> "address" : { ...> "street" : "Ramar Street", ...> "village" : "Sri Rama Kuppam", ...> "post" : "seethanjeri", ...> "pincode" : "602026", ...> "taluk" : "Uthukkottai", ...> "nation" : "USA" ...> }, ...> "education":"computer engineering", ...> "occupation" : "software professional" ...> } ...> ]) [ { "_id" : "myfriends/142787", "_key" : "142787", "_rev" : "142787" }, { "_id" : "myfriends/142791", "_key" : "142791", "_rev" : "142791" } ] 127.0.0.1:8529@uvdb>

Find or Query Data...

We can use the collection.byExample() method to retrieve data from a collection in ArangoDB... This method can Fetches all documents from a collection that match the specified filter or criteria and returns a cursor. You can specify the filter or criteria in a document and pass as a parameter to the byExample() method.

Syntax :
db.collection.byExample( { "field": "value" } );
We have to use toArray, next, or hasNext to access the result.

For example to find document which consists name field with value balu..

db.myfriends.byExample( { "name": "balu" } ).toArray();
Sample output :
127.0.0.1:8529@_uvdb> db.myfriends.byExample( { "name": "balu" } ).toArray(); [ { "_key" : "142787", "_id" : "myfriends/142787", "_rev" : "142787", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education" : "computer engineering", "name" : "balu", "occupation" : "software professional" }, { "_key" : "139885", "_id" : "myfriends/139885", "_rev" : "139885", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education" : "computer engineering", "name" : "balu", "occupation" : "software professional" } ] 127.0.0.1:8529@_uvdb>
We can also use collection.document(object) ...
The document method finds a document given an object object containing the _id or _key attribute. The method returns the document if it can be found. If both attributes are given, the _id takes precedence, it is an error, if the collection part of the _id does not match the collection.
AQL (ArangoDB Query Language) provides very extensive range of options to query or perform CURD operations..

The db.collection.toArray(); method will return all documents in a collection..

For example, db.myfriends.toArray(); will return all documents in a collection named myfriends..

db.myfriends.toArray();
Sample output :
127.0.0.1:8529@_uvdb> db.myfriends.toArray(); [ { "_key" : "142787", "_id" : "myfriends/142787", "_rev" : "142787", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education" : "computer engineering", "name" : "balu", "occupation" : "software professional" }, { "_key" : "142791", "_id" : "myfriends/142791", "_rev" : "142791", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "USA" }, "education" : "computer engineering", "name" : "babu", "occupation" : "software professional" }, { "_key" : "139885", "_id" : "myfriends/139885", "_rev" : "139885", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education" : "computer engineering", "name" : "balu", "occupation" : "software professional" } ] 127.0.0.1:8529@uvdb>

Updating Data..

Update operations can modify/replace existing documents in a collection. The update method accepts 2 parameters:

Syntax :
collection.update(selector, data)

Updates an existing document described by the selector, which must be an object containing the _id or _key attribute. There must be a document with that _id or _key in the current collection. This document is then patched with the data given as second argument. Any attribute _id, _key or _rev in data is ignored.

db.myfriends.update({"_key" : "139885"}, {"name":"madhu"});
Sample Output :
127.0.0.1:8529@_uvdb> db.myfriends.update({"_key" : "139885"}, {"name":"madhu"}); { "_id" : "myfriends/139885", "_key" : "139885", "_rev" : "151996", "_oldRev" : "139885" } 127.0.0.1:8529@_uvdb>

see the document collections after updated..

Sample Output :
127.0.0.1:8529@_uvdb> db.myfriends.toArray(); [ { "_key" : "142787", "_id" : "myfriends/142787", "_rev" : "142787", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education" : "computer engineering", "name" : "balu", "occupation" : "software professional" }, { "_key" : "142791", "_id" : "myfriends/142791", "_rev" : "142791", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "USA" }, "education" : "computer engineering", "name" : "babu", "occupation" : "software professional" }, { "_key" : "139885", "_id" : "myfriends/139885", "_rev" : "151996", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education" : "computer engineering", "name" : "madhu", "occupation" : "software professional" } ] 127.0.0.1:8529@uvdb>

Replace a Document

Syntax :
collection.replace(selector, data)

Replaces an existing document described by the selector, which must be an object containing the _id or _key attribute. There must be a document with that _id or _key in the current collection. This document is then replaced with the data given as second argument. Any attribute _id, _key or _rev in data is ignored.

db.myfriends.replace({"_key" : "142787"}, {"name":"abilash"});

The above will replace document with key 142787 with new document specified as second parameter.

Sample Output :
127.0.0.1:8529@_uvdb> db.myfriends.replace({"_key" : "142787"}, {"name":"abilash"}); { "_id" : "myfriends/142787", "_key" : "142787", "_rev" : "164288", "_oldRev" : "142787" } 127.0.0.1:8529@uvdb>

Now look at the document.. compare it with old one..

127.0.0.1:8529@_uvdb> db.myfriends.toArray(); [ { "_key" : "142787", "_id" : "myfriends/142787", "_rev" : "164288", "name" : "abilash" }, { "_key" : "142791", "_id" : "myfriends/142791", "_rev" : "142791", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "USA" }, "education" : "computer engineering", "name" : "babu", "occupation" : "software professional" }, { "_key" : "139885", "_id" : "myfriends/139885", "_rev" : "151996", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education" : "computer engineering", "name" : "madhu", "occupation" : "software professional" } ] 127.0.0.1:8529@uvdb>

Removing Document from Collection..

We can easily remove data with collection.remove() method..

collection.remove(selector);

Removes a document described by the selector, which must be an object containing the _id or _key attribute. There must be a document with that _id or _key in the current collection. This document is then removed.

db.myfriends.remove({"_key" : "142791"});

This will remove document with key value "142791" .

Sample Output :
127.0.0.1:8529@_uvdb> db.myfriends.remove({"_key" : "142791"}); { "_id" : "myfriends/142791", "_key" : "142791", "_rev" : "142791" } 127.0.0.1:8529@uvdb>

After this operation check the documents.. you can notice that one document got removed from collection..

127.0.0.1:8529@_uvdb> db.myfriends.toArray() [ { "_key" : "142787", "_id" : "myfriends/142787", "_rev" : "164288", "name" : "abilash" }, { "_key" : "139885", "_id" : "myfriends/139885", "_rev" : "151996", "address" : { "street" : "Ramar Street", "village" : "Sri Rama Kuppam", "post" : "seethanjeri", "pincode" : "602026", "taluk" : "Uthukkottai", "nation" : "India" }, "education" : "computer engineering", "name" : "madhu", "occupation" : "software professional" } ] 127.0.0.1:8529@uvdb>
Note : Note that the above examples use notation that looks like db.collection.method().. The beauty of ArangoDB is, instead of above, we can also use db._method(); like notation..
Means, we can use db._document(); instead of db.collection.document(); ..
You can find more about this here..

Accessing ArangoDB From Web interface :

ArangoDB comes with a built-in web interface for administration. The web interface can be accessed via the URL:

http://127.0.0.1:8529

Or

http://localhost:8529

To get familiar with the database system you can use the web interface (code name Aardvark) for basic interaction. The web interface will become available shortly after you started arangod. You can access it in your browser at http://localhost:8529..

If everything works as expected, you should see the login view..


ArangoDB web interface login view

Next you will be asked which database to use. Every server instance comes with a _system database. Select this database to continue.


ArangoDB web interface db select

You should then be presented the dashboard with server statistics like this..


ArangoDB web interface graph view

For a more detailed description of the interface, see Web Interface.

SQL to ArangoDB..

Here you can find SQL to ArangoDB mapping guide....

Hi friends, If you found any issue or typo error, please feel free to report it.. You can either open an issue on github or you can also report it on our Facebook Page via message(www.fb.com/opensourceinside) .