SlideShare a Scribd company logo
© 2013 triAGENS GmbH | 2013-06-18
Query Languages
for Document Stores
2013-06-18
Jan Steemann
© 2013 triAGENS GmbH | 2013-06-18
me
 I'm a software developer
 working at triAGENS GmbH, CGN
 on - a document store
© 2013 triAGENS GmbH | 2013-06-18
Documents
© 2013 triAGENS GmbH | 2013-06-18
Documents
 documents are self-contained,
aggregate data structures...
 ...consisting of named and typed attributes,
which can be nested / hierarchical
 documents can be used to model complex
business objects
© 2013 triAGENS GmbH | 2013-06-18
Example order document
{ 
  "id": "abc­100­22", 
  "date": "2013­04­26" 
  "customer": {
    "id": "c­199­023",
    "name": "acme corp."
  },
  "items": [ { 
      "id": "p­123",
      "quantity": 1,
      "price": 25.13
  } ]
}  
© 2013 triAGENS GmbH | 2013-06-18
Document stores
 document stores are databases
specialised in handling documents
 they've been around for a while
 got really popular with the NoSQL buzz
(CouchDB, MongoDB, ...)
© 2013 triAGENS GmbH | 2013-06-18
Why use
Document
Stores?
© 2013 triAGENS GmbH | 2013-06-18
Saving programming language data
 document stores allow saving a
programming language object as a whole
 your programming language object
becomes a document in the database,
without the need for much transformation
 compare this to saving data in a relational
database...
© 2013 triAGENS GmbH | 2013-06-18
Persistence the relational way
orders
id date
1 2013-04-20
2 2013-04-21
3 2013-04-21
4 2013-04-22
customers
customer
c1
c2
c1
c3
id name
c1
c2
c3
acme corp.
sample.com
abc co.
orderitems
1
order item
1
price quantity
23.25 1
© 2013 triAGENS GmbH | 2013-06-18
Benefits of document stores
 no impedance mismatch,
no complex object-relational mapping,
no normalisation requirements
 querying documents is often easier and
faster than querying highly normalised
relational data
© 2013 triAGENS GmbH | 2013-06-18
Schema-less
 in document stores, there is no "table"-
schema as in the relational world
 each document can have different attributes
 there is no such thing as ALTER TABLE
 that's why document stores are called
schema-less or schema-free
© 2013 triAGENS GmbH | 2013-06-18
Querying
Document
Stores
© 2013 triAGENS GmbH | 2013-06-18
Querying by document id is easy
 every document store allows querying a
single document at a time
 accessing documents by their unique ids is
almost always dead-simple
© 2013 triAGENS GmbH | 2013-06-18
Complex queries?
 what if you want to run complex queries (e.g.
projections, filters, aggregations,
transformations, joins, ...)??
 let's check the available options in some of
the popular document stores
© 2013 triAGENS GmbH | 2013-06-18
CouchDB: map-reduce
 querying by something else than document
key / id requires writing a view
 views are JavaScript functions that are
stored inside the database
 views are populated by incremental map-
reduce
© 2013 triAGENS GmbH | 2013-06-18
map-reduce
 the map function is applied on each document
(that changed)
 map can filter out non-matching documents
 or emit modified or unmodified versions of them
 emitted documents can optionally be passed into
a reduce function
 reduce is called with groups of similar
documents and can thus perform aggregation
© 2013 triAGENS GmbH | 2013-06-18
CouchDB map-reduce example
map = function (doc) {
  var i, n = doc.orderItems.length;
  for (i = 0; i < n; ++i) {
    emit(doc.orderItems[i], 1);
  }
};
reduce = function (keys, values, rereduce) {
  if (rereduce) {
    return sum(values);
  }
  return values.length;
};
© 2013 triAGENS GmbH | 2013-06-18
map-reduce
 map-reduce is generic and powerful
 provides a programming language
 need to create views for everything that is
queried
 access to a single "table" at a time (no
cross-"table" views)
 a bit clumsy for ad-hoc exploratory queries
© 2013 triAGENS GmbH | 2013-06-18
MongoDB: find()
 ad-hoc queries in MongoDB are much easier
 can directly apply filters on collections,
allowing to find specific documents easily:
mongo> db.orders.find({ 
  "customer": { 
    "id": "c1",
    "name": "acme corp."
  }
});
© 2013 triAGENS GmbH | 2013-06-18
MongoDB: complex filters
 can filter on any document attribute or
sub-attribute
 indexes will automatically be used if present
 nesting filters allows complex queries
 quite flexible and powerful, but tends to be
hard to use and read for more complex
queries
© 2013 triAGENS GmbH | 2013-06-18
MongoDB: complex filtering
mongo> db.users.find({ 
  "$or": [ 
    { 
      "active": true 
    }, 
    { 
      "age": { 
        "$gte": 40 
      } 
    } 
  ]
});
© 2013 triAGENS GmbH | 2013-06-18
MongoDB: more options
 can also use JavaScript functions for filtering,
or JavaScript map-reduce
 several aggregation functions are also
provided
 neither option allows running cross-"table"
queries
© 2013 triAGENS GmbH | 2013-06-18
Why not use a
Query
Language?
© 2013 triAGENS GmbH | 2013-06-18
Query languages
 a good query language should
 allow writing both simple and complex
queries, without having to switch the
methodology
 provide the required features for filtering,
aggregation, joining etc.
 hide the database internals
© 2013 triAGENS GmbH | 2013-06-18
SQL
 in the relational world, there is one accepted
general-purpose query language: SQL
 it is quite well-known and mature:
 35+ years of experience
 many developers and established tools
around it
 standardised (but mind the "dialects"!)
© 2013 triAGENS GmbH | 2013-06-18
SQL in document stores?
 SQL is good at handling relational data
 not good at handling multi-valued or
hierchical attributes, which are common in
documents
 (too) powerful: SQL provides features many
document stores intentionally lack (e.g. joins,
transactions)
 SQL has not been adopted by document
stores yet
© 2013 triAGENS GmbH | 2013-06-18
Query
Languages
for Document
Stores
© 2013 triAGENS GmbH | 2013-06-18
XQuery?
 XQuery is a query and programming
language
 targeted mainly at processing XML data
 can process hierarchical data
 very powerful and extensible
 W3C recommendation
© 2013 triAGENS GmbH | 2013-06-18
XQuery
 XQuery has found most adoption in the area
of XML processing
 today people want to use JSON, not XML
 XQuery not available in popular document
stores
© 2013 triAGENS GmbH | 2013-06-18
ArangoDB Query Language (AQL)
 ArangoDB provides AQL, a query language
made for JSON document processing
 it allows running complex queries on
documents, including joins and aggregation
 language syntax was inspired by XQuery and
provides similar concepts such as
FOR, LET, RETURN, ...
 the language integrates JSON "naturally"
© 2013 triAGENS GmbH | 2013-06-18
AQL example
FOR order IN orders
  FILTER order.status == "processed"
  LET itemsValue = SUM((
    FOR item IN order.items
      FILTER item.status == "confirmed"
      RETURN item.price * item.quantity
  ))
  FILTER itemsValue >= 500
  RETURN {
    "items"      : order.items,
    "itemsValue" : itemsValue,
    "itemsCount" : LENGTH(order.items)
  }
© 2013 triAGENS GmbH | 2013-06-18
AQL: some features
 queries can combine data from multiple
"tables"
 this allows joins using any document
attributes or sub-attributes
 indexes will be used if present
© 2013 triAGENS GmbH | 2013-06-18
AQL: join example
FOR user IN users
  FILTER user.id == 1234
  RETURN {
    "user"  : user,
    "posts" : (FOR post IN blogPosts
      FILTER post.userId == user.id &&
             post.date >= '2013­06­13'          
  
      RETURN post
    )
  }
© 2013 triAGENS GmbH | 2013-06-18
AQL: additional features
 AQL provides basic functionality to query
graphs, too
 the language can be extended with user-
defined JavaScript functions
© 2013 triAGENS GmbH | 2013-06-18
JSONiq
 JSONiq is a data processing and query
language for handling JSON data
 it is based on XQuery, thus provides the same
FLWOR expressions: FOR, LET, WHERE,
ORDER, ...
 JSON is integrated "naturally"
 most of the XML handling is removed
© 2013 triAGENS GmbH | 2013-06-18
JSONiq: example
for $order in collection("orders")
  where $order.customer.id eq "abc­123"
  return {
    customer : $order.customer,
    items    : $order.items
  }
© 2013 triAGENS GmbH | 2013-06-18
JSONiq: join example
for $post in collection("posts")
  let $postId := $post.id
  for $comment in collection("comments")
    where $comment.postId eq $postId
    group by $postId
    order by count($comment) descending
    return {
      id       : $postId,
      comments : count($comment)
    }
© 2013 triAGENS GmbH | 2013-06-18
JSONiq
 JSONiq is a generic, database-agnostic
language
 it can be extended with user-defined XQuery
functions
 JSONiq is currently not implemented inside
any document database...
© 2013 triAGENS GmbH | 2013-06-18
JSONiq
 ...but it can be used via a service (at 28.io)
 the service provides the JSONiq query
language and implements functionality not
provided by a specific database
 such features are implemented client-side,
e.g. joins for MongoDB
© 2013 triAGENS GmbH | 2013-06-18
Summary
© 2013 triAGENS GmbH | 2013-06-18
Summary
 today's document stores provide different,
proprietary mechanisms for querying data
 there is currently no standard query
mechanism for document stores as there is
in the relational world (SQL)
© 2013 triAGENS GmbH | 2013-06-18
Summary
 you CAN use query languages in document
stores today, e.g. AQL and JSONiq
 if you like the idea, give them a try, provide
feedback and contribute!

More Related Content

PDF
Query mechanisms for NoSQL databases
PDF
Domain Driven Design and NoSQL TLV
PDF
Multi-model databases and node.js
PDF
Extensible Database APIs and their role in Software Architecture
PDF
Jan Steemann: Modelling data in a schema free world (Talk held at Froscon, 2...
PDF
Webinar: How native multi model works in ArangoDB
PDF
Backbone using Extensible Database APIs over HTTP
PDF
Processing large-scale graphs with Google Pregel
Query mechanisms for NoSQL databases
Domain Driven Design and NoSQL TLV
Multi-model databases and node.js
Extensible Database APIs and their role in Software Architecture
Jan Steemann: Modelling data in a schema free world (Talk held at Froscon, 2...
Webinar: How native multi model works in ArangoDB
Backbone using Extensible Database APIs over HTTP
Processing large-scale graphs with Google Pregel

What's hot (20)

PPTX
NoSQL and MapReduce
PDF
Introduction to ArangoDB (nosql matters Barcelona 2012)
PDF
Multi model-databases
PPT
5 Data Modeling for NoSQL 1/2
PDF
guacamole: an Object Document Mapper for ArangoDB
PDF
FOXX - a Javascript application framework on top of ArangoDB
PDF
Multi model-databases 29-10-2014 LJC
PDF
ArangoDB 3.7 Roadmap: Performance at Scale
PDF
Oslo bekk2014
PDF
Ssn0020 ssis 2012 for beginners
PDF
PPTX
PPTX
Nosql
PPT
Schemaless Databases
PPT
Object Relational Mapping with LINQ To SQL
PDF
Deep Dive on ArangoDB
PDF
Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...
DOC
Assignment_4
PPTX
Introduction à DocumentDB
PDF
Big Challenges in Data Modeling: NoSQL and Data Modeling
NoSQL and MapReduce
Introduction to ArangoDB (nosql matters Barcelona 2012)
Multi model-databases
5 Data Modeling for NoSQL 1/2
guacamole: an Object Document Mapper for ArangoDB
FOXX - a Javascript application framework on top of ArangoDB
Multi model-databases 29-10-2014 LJC
ArangoDB 3.7 Roadmap: Performance at Scale
Oslo bekk2014
Ssn0020 ssis 2012 for beginners
Nosql
Schemaless Databases
Object Relational Mapping with LINQ To SQL
Deep Dive on ArangoDB
Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...
Assignment_4
Introduction à DocumentDB
Big Challenges in Data Modeling: NoSQL and Data Modeling
Ad

Viewers also liked (20)

PPTX
Introduction to NoSQL Databases
KEY
NoSQL Databases: Why, what and when
PDF
SQL vs. NoSQL
PPTX
NoSQL Databases for Implementing Data Services – Should I Care?
PDF
Architektur von Big Data Lösungen
PDF
Chaordic - BigData e MapReduce - Robson Motta
PDF
Firebase Adventures - Going above and beyond in Realtime
PDF
Drupal 6 Database layer
PDF
Cassandra - Eine Einführung
PPTX
Web Services and Mobile
PPTX
Principles of Service-Oriented Architecture
PDF
Leveraging SAP HANA with Apache Hadoop and SAP Analytics
PPTX
Leveraging SAP, Hadoop, and Big Data to Redefine Business
PDF
Lista de-precios-compugreiff-enero-14-2013
PDF
Industrial Ecology KIGAM CSIRO
PDF
Mercado Livre Experience - Matias Gualino
DOC
Zaragoza Turismo 36
PPTX
Personal branding project
PDF
Creative crowdsourcing - Specwork reflections and proposals - Travail spécula...
PPTX
Honduras Medical Mission
Introduction to NoSQL Databases
NoSQL Databases: Why, what and when
SQL vs. NoSQL
NoSQL Databases for Implementing Data Services – Should I Care?
Architektur von Big Data Lösungen
Chaordic - BigData e MapReduce - Robson Motta
Firebase Adventures - Going above and beyond in Realtime
Drupal 6 Database layer
Cassandra - Eine Einführung
Web Services and Mobile
Principles of Service-Oriented Architecture
Leveraging SAP HANA with Apache Hadoop and SAP Analytics
Leveraging SAP, Hadoop, and Big Data to Redefine Business
Lista de-precios-compugreiff-enero-14-2013
Industrial Ecology KIGAM CSIRO
Mercado Livre Experience - Matias Gualino
Zaragoza Turismo 36
Personal branding project
Creative crowdsourcing - Specwork reflections and proposals - Travail spécula...
Honduras Medical Mission
Ad

Similar to Query Languages for Document Stores (20)

PDF
Introduction and overview ArangoDB query language AQL
PDF
Multi model-databases
PDF
An E-commerce App in action built on top of a Multi-model Database
PDF
An introduction to multi-model databases
PDF
An introduction to multi-model databases
PDF
ArangoDB – A different approach to NoSQL
PDF
AvocadoDB query language (DRAFT!)
PDF
Which Questions We Should Have
PPTX
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
PDF
QB Into the Box 2018
PDF
Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...
PDF
From SQL to MongoDB
PDF
Complex queries in a distributed multi-model database
PPTX
MongoDB Evenings DC: MongoDB - The New Default Database for Giant Ideas
PPTX
UNIT-1 MongoDB.pptx
PDF
MongoDB
PPT
Couch db
PDF
Open Source World June '21 -- JSON Within a Relational Database
PPTX
MongoDB
PDF
MySQL Document Store -- SCaLE 17x Presentation
Introduction and overview ArangoDB query language AQL
Multi model-databases
An E-commerce App in action built on top of a Multi-model Database
An introduction to multi-model databases
An introduction to multi-model databases
ArangoDB – A different approach to NoSQL
AvocadoDB query language (DRAFT!)
Which Questions We Should Have
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
QB Into the Box 2018
Max Neunhöffer – Joins and aggregations in a distributed NoSQL DB - NoSQL mat...
From SQL to MongoDB
Complex queries in a distributed multi-model database
MongoDB Evenings DC: MongoDB - The New Default Database for Giant Ideas
UNIT-1 MongoDB.pptx
MongoDB
Couch db
Open Source World June '21 -- JSON Within a Relational Database
MongoDB
MySQL Document Store -- SCaLE 17x Presentation

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
cuic standard and advanced reporting.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation theory and applications.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectroscopy.pptx food analysis technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Dropbox Q2 2025 Financial Results & Investor Presentation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
The AUB Centre for AI in Media Proposal.docx
Network Security Unit 5.pdf for BCA BBA.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
cuic standard and advanced reporting.pdf
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MIND Revenue Release Quarter 2 2025 Press Release
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)

Query Languages for Document Stores

  • 1. © 2013 triAGENS GmbH | 2013-06-18 Query Languages for Document Stores 2013-06-18 Jan Steemann
  • 2. © 2013 triAGENS GmbH | 2013-06-18 me  I'm a software developer  working at triAGENS GmbH, CGN  on - a document store
  • 3. © 2013 triAGENS GmbH | 2013-06-18 Documents
  • 4. © 2013 triAGENS GmbH | 2013-06-18 Documents  documents are self-contained, aggregate data structures...  ...consisting of named and typed attributes, which can be nested / hierarchical  documents can be used to model complex business objects
  • 5. © 2013 triAGENS GmbH | 2013-06-18 Example order document {    "id": "abc­100­22",    "date": "2013­04­26"    "customer": {     "id": "c­199­023",     "name": "acme corp."   },   "items": [ {        "id": "p­123",       "quantity": 1,       "price": 25.13   } ] }  
  • 6. © 2013 triAGENS GmbH | 2013-06-18 Document stores  document stores are databases specialised in handling documents  they've been around for a while  got really popular with the NoSQL buzz (CouchDB, MongoDB, ...)
  • 7. © 2013 triAGENS GmbH | 2013-06-18 Why use Document Stores?
  • 8. © 2013 triAGENS GmbH | 2013-06-18 Saving programming language data  document stores allow saving a programming language object as a whole  your programming language object becomes a document in the database, without the need for much transformation  compare this to saving data in a relational database...
  • 9. © 2013 triAGENS GmbH | 2013-06-18 Persistence the relational way orders id date 1 2013-04-20 2 2013-04-21 3 2013-04-21 4 2013-04-22 customers customer c1 c2 c1 c3 id name c1 c2 c3 acme corp. sample.com abc co. orderitems 1 order item 1 price quantity 23.25 1
  • 10. © 2013 triAGENS GmbH | 2013-06-18 Benefits of document stores  no impedance mismatch, no complex object-relational mapping, no normalisation requirements  querying documents is often easier and faster than querying highly normalised relational data
  • 11. © 2013 triAGENS GmbH | 2013-06-18 Schema-less  in document stores, there is no "table"- schema as in the relational world  each document can have different attributes  there is no such thing as ALTER TABLE  that's why document stores are called schema-less or schema-free
  • 12. © 2013 triAGENS GmbH | 2013-06-18 Querying Document Stores
  • 13. © 2013 triAGENS GmbH | 2013-06-18 Querying by document id is easy  every document store allows querying a single document at a time  accessing documents by their unique ids is almost always dead-simple
  • 14. © 2013 triAGENS GmbH | 2013-06-18 Complex queries?  what if you want to run complex queries (e.g. projections, filters, aggregations, transformations, joins, ...)??  let's check the available options in some of the popular document stores
  • 15. © 2013 triAGENS GmbH | 2013-06-18 CouchDB: map-reduce  querying by something else than document key / id requires writing a view  views are JavaScript functions that are stored inside the database  views are populated by incremental map- reduce
  • 16. © 2013 triAGENS GmbH | 2013-06-18 map-reduce  the map function is applied on each document (that changed)  map can filter out non-matching documents  or emit modified or unmodified versions of them  emitted documents can optionally be passed into a reduce function  reduce is called with groups of similar documents and can thus perform aggregation
  • 17. © 2013 triAGENS GmbH | 2013-06-18 CouchDB map-reduce example map = function (doc) {   var i, n = doc.orderItems.length;   for (i = 0; i < n; ++i) {     emit(doc.orderItems[i], 1);   } }; reduce = function (keys, values, rereduce) {   if (rereduce) {     return sum(values);   }   return values.length; };
  • 18. © 2013 triAGENS GmbH | 2013-06-18 map-reduce  map-reduce is generic and powerful  provides a programming language  need to create views for everything that is queried  access to a single "table" at a time (no cross-"table" views)  a bit clumsy for ad-hoc exploratory queries
  • 19. © 2013 triAGENS GmbH | 2013-06-18 MongoDB: find()  ad-hoc queries in MongoDB are much easier  can directly apply filters on collections, allowing to find specific documents easily: mongo> db.orders.find({    "customer": {      "id": "c1",     "name": "acme corp."   } });
  • 20. © 2013 triAGENS GmbH | 2013-06-18 MongoDB: complex filters  can filter on any document attribute or sub-attribute  indexes will automatically be used if present  nesting filters allows complex queries  quite flexible and powerful, but tends to be hard to use and read for more complex queries
  • 21. © 2013 triAGENS GmbH | 2013-06-18 MongoDB: complex filtering mongo> db.users.find({    "$or": [      {        "active": true      },      {        "age": {          "$gte": 40        }      }    ] });
  • 22. © 2013 triAGENS GmbH | 2013-06-18 MongoDB: more options  can also use JavaScript functions for filtering, or JavaScript map-reduce  several aggregation functions are also provided  neither option allows running cross-"table" queries
  • 23. © 2013 triAGENS GmbH | 2013-06-18 Why not use a Query Language?
  • 24. © 2013 triAGENS GmbH | 2013-06-18 Query languages  a good query language should  allow writing both simple and complex queries, without having to switch the methodology  provide the required features for filtering, aggregation, joining etc.  hide the database internals
  • 25. © 2013 triAGENS GmbH | 2013-06-18 SQL  in the relational world, there is one accepted general-purpose query language: SQL  it is quite well-known and mature:  35+ years of experience  many developers and established tools around it  standardised (but mind the "dialects"!)
  • 26. © 2013 triAGENS GmbH | 2013-06-18 SQL in document stores?  SQL is good at handling relational data  not good at handling multi-valued or hierchical attributes, which are common in documents  (too) powerful: SQL provides features many document stores intentionally lack (e.g. joins, transactions)  SQL has not been adopted by document stores yet
  • 27. © 2013 triAGENS GmbH | 2013-06-18 Query Languages for Document Stores
  • 28. © 2013 triAGENS GmbH | 2013-06-18 XQuery?  XQuery is a query and programming language  targeted mainly at processing XML data  can process hierarchical data  very powerful and extensible  W3C recommendation
  • 29. © 2013 triAGENS GmbH | 2013-06-18 XQuery  XQuery has found most adoption in the area of XML processing  today people want to use JSON, not XML  XQuery not available in popular document stores
  • 30. © 2013 triAGENS GmbH | 2013-06-18 ArangoDB Query Language (AQL)  ArangoDB provides AQL, a query language made for JSON document processing  it allows running complex queries on documents, including joins and aggregation  language syntax was inspired by XQuery and provides similar concepts such as FOR, LET, RETURN, ...  the language integrates JSON "naturally"
  • 31. © 2013 triAGENS GmbH | 2013-06-18 AQL example FOR order IN orders   FILTER order.status == "processed"   LET itemsValue = SUM((     FOR item IN order.items       FILTER item.status == "confirmed"       RETURN item.price * item.quantity   ))   FILTER itemsValue >= 500   RETURN {     "items"      : order.items,     "itemsValue" : itemsValue,     "itemsCount" : LENGTH(order.items)   }
  • 32. © 2013 triAGENS GmbH | 2013-06-18 AQL: some features  queries can combine data from multiple "tables"  this allows joins using any document attributes or sub-attributes  indexes will be used if present
  • 33. © 2013 triAGENS GmbH | 2013-06-18 AQL: join example FOR user IN users   FILTER user.id == 1234   RETURN {     "user"  : user,     "posts" : (FOR post IN blogPosts       FILTER post.userId == user.id &&              post.date >= '2013­06­13'                    RETURN post     )   }
  • 34. © 2013 triAGENS GmbH | 2013-06-18 AQL: additional features  AQL provides basic functionality to query graphs, too  the language can be extended with user- defined JavaScript functions
  • 35. © 2013 triAGENS GmbH | 2013-06-18 JSONiq  JSONiq is a data processing and query language for handling JSON data  it is based on XQuery, thus provides the same FLWOR expressions: FOR, LET, WHERE, ORDER, ...  JSON is integrated "naturally"  most of the XML handling is removed
  • 36. © 2013 triAGENS GmbH | 2013-06-18 JSONiq: example for $order in collection("orders")   where $order.customer.id eq "abc­123"   return {     customer : $order.customer,     items    : $order.items   }
  • 37. © 2013 triAGENS GmbH | 2013-06-18 JSONiq: join example for $post in collection("posts")   let $postId := $post.id   for $comment in collection("comments")     where $comment.postId eq $postId     group by $postId     order by count($comment) descending     return {       id       : $postId,       comments : count($comment)     }
  • 38. © 2013 triAGENS GmbH | 2013-06-18 JSONiq  JSONiq is a generic, database-agnostic language  it can be extended with user-defined XQuery functions  JSONiq is currently not implemented inside any document database...
  • 39. © 2013 triAGENS GmbH | 2013-06-18 JSONiq  ...but it can be used via a service (at 28.io)  the service provides the JSONiq query language and implements functionality not provided by a specific database  such features are implemented client-side, e.g. joins for MongoDB
  • 40. © 2013 triAGENS GmbH | 2013-06-18 Summary
  • 41. © 2013 triAGENS GmbH | 2013-06-18 Summary  today's document stores provide different, proprietary mechanisms for querying data  there is currently no standard query mechanism for document stores as there is in the relational world (SQL)
  • 42. © 2013 triAGENS GmbH | 2013-06-18 Summary  you CAN use query languages in document stores today, e.g. AQL and JSONiq  if you like the idea, give them a try, provide feedback and contribute!