ArangoDB
/* Using Javascriptin the database */
Jan Steemann, triAGENS, Cologne
www.arangodb.org © [email protected]
ArangoDBbasics
www.arangodb.org © [email protected]
ArangoDB.explain()
{ "type": "NoSQL database", "openSource": true, "version": 1.0, "builtWith": [ "C", "C++", "js" ], "Javascript": [ "client side", "server side" ], "uses": [ "V8" ]}
www.arangodb.org © [email protected]
Documentsand collections
ArangoDB is a database that works with documents
Documents are sets of name / value pairs (think of JSON objects), e.g.
{ "name": "Jan", "age": 37 }
Documents are organised in collections (like tables in relational databases)
www.arangodb.org © [email protected]
Data types: JSON!
ArangoDB operates on JSON documents
JSON data can be saved as-is:
db.users.save({ "name": "Jan", "uses": [ "vi", "js", "C++" ]});
www.arangodb.org © [email protected]
Schema-freeDocuments can be heterogenous – even in the same collection, e.g.
{ "name": "Jan", "age": 37 },{ "name": "Tim", "likes": [ "js" ] },{ "name": { "first": "Patrick", "last": "Star" }}
No need to care about schemas
www.arangodb.org © [email protected]
API & protocolsArangoDB server functionality is exposed via an HTTP REST API
ArangoDB answers HTTP queries, so it can be used from the browser
Simple to use from Javascript clients
(3rd party) drivers available for node.js, Ruby, PHP, ...
Javascript-enabled client shell provided
www.arangodb.org © [email protected]
Querying
www.arangodb.org © [email protected]
Querying is simple
Query a document by its unique id / key:db._document("users/9558905");
Query by providing an example:db.users.byExample({ "name": "Jan", "age": 37});
www.arangodb.org © [email protected]
Indexes
ArangoDB allows querying on any document attributes or sub-attributes
Secondary indexes can be created for higher query performance:
• Hash indexes (equality queries)
• Skiplists (range queries)
• 2d geo indexes (location queries)
www.arangodb.org © [email protected]
Geo index examples
// get b a r n ea r es t t o coor din a t edb.bars.near(48.51, 2.21).limit(1);
// get a ll s h op s w it h in r a diu s// a r ou n d coor din a t edb.shops.within(48.51, 2.21, rad);
www.arangodb.org © [email protected]
References
ArangoDB can store references between documents
References are documents with two endpoints (the documents they connect)
Reference documents can carry own attributes
www.arangodb.org © [email protected]
References exampleUsers documents:
{ "name": "Jan", "age": 37} { "name": "Tim", "city": "Paris"}
Relations documents:(references)
{ "_from": "users/jan", "_to": "users/tim", "type": "knows",}
// qu er y ou t b ou n d r ela t ion s f r om "J a n "db.relations.outEdges(jan); // => tim
www.arangodb.org © [email protected]
Graph queries
References make it possible to process graphs with ArangoDB
Some special functions are provided to determine paths in a graph etc.
Can write own Javascript functions for special traversals
www.arangodb.org © [email protected]
Query language
ArangoDB can also answer complexSQL-like queries
Such queries are expressed in ArangoDB's textual query language
This language allows joins, sub-queries, aggregation etc.
www.arangodb.org © [email protected]
Example queryFOR u IN users FILTER u.addr.country == "US" && (u.isConfirmed == true || u.age >= 18) LET userLogins = ( FOR l IN logins FILTER l.userId == u.id RETURN l ) RETURN { "user": u, "logins": LENGTH(userLogins) }
S u b qu er y
R es u lt
F ilt er
It er a t or
www.arangodb.org © [email protected]
Server side „actions“
www.arangodb.org © [email protected]
Application server
ArangoDB can answer web requests directly
This also makes it an application server
Users can extend its functionality with server side Javascript „actions“
Actions are user-defined functions that contain custom business logic
www.arangodb.org © [email protected]
Actions
Actions are bound to URLs and executed when URLs are called, e.g.
/users?name=... => function(...)/users/.../friends => function(...)
www.arangodb.org © [email protected]
Actions examplefunction (req, res) { // get r equ es t ed u s er f r om d b , // n a m e is r ea d f r om U R L p a r a m et er var u = db.users.byExample({ "username": req.urlParameters.name });
// r em ov e p a s s w or d h a s h delete u.hashedPassword;
// b ef or e r et u r n in g t o ca ller actions.resultOk(req, res, 200, u);}
www.arangodb.org © [email protected]
Actions – Use casesFilter out sensitive data before responding
Validate input
Check privileges
Check and enforce constraints
Aggregate data from multiple queries into a single response
Carry out data-intensive operations
www.arangodb.org © [email protected]
Summary
www.arangodb.org © [email protected]
ArangoDB - summary
Flexible in terms of data modelling and querying
API is based on web standards:HTTP, REST, JSON
Easy to use from Javascript clients
Can be used as application server
Functionality can be extended with server side Javascript „actions“
www.arangodb.org © [email protected]
Thanks!Any questions?
Grazie
¡Gracias!
Хвала
Ευχαριστώ
고마워
Danke
Спасибо
Teşekkürler
Merci!
Dank je wel
ありがとう
Tack så mycket
www.arangodb.org © [email protected]
Give it a try!ArangoDB source repository: https://www.github.com/triAGENS/ArangoDB(use master branch)
Website: http://www.arangodb.org/
Builds available for Homebrew and several Linux distributions
Twitter: #arangodb, @arangodb
Google group: ArangoDB
www.arangodb.org © [email protected]
Roadmap
MVCC / ACID transactions
Triggers
Synchronous and asynchronous replication
www.arangodb.org © [email protected]
Stay in Touch:
• Fork me on github
• Google Group: ArangoDB
• Twitter: @steemann & @arangodb
• www.arangodb.org
Thank you!