RQL Reference

Resource Query Language (RQL) is a query language for web.

Read the draft of specification and documentation for more information.

Click on operator descriptions shows/hides additional details.
Following button shows/hides details for all operators:

Examples

An example of an RQL for finding resources with a category of "toy" and sorted by price in ascending order:
category=toy&sort(+price)

RQL is a compatible superset of standard HTML form URL encoding. The following queries are identical:
eq(foo,3)
foo=3

Such that this can be used in URIs like:
https://example.org/data?foo=3

We can write a query that finds resources with a "price" property below 10 with a "lt" operator using FIQL syntax:
price=lt=10
lt(price,10)

One can combine conditions with multiple operators with "&":
foo=3&price=lt=10
eq(foo,3)&lt(price,10)
and(eq(foo,3),lt(price,10))

The | operator can be used to indicate an "or" operation. We can also use paranthesis to group expressions. For example:
(foo=3|foo=bar)&price=lt=10

Reference

Queries
select select(<property>,<property>,...)
Trims each object down o the set of properties defined in the arguments
values values(<property>)
Returns an array of the given property value for each object
distinct distinct()
Returns a result set with duplicates removed
limit limit(count,start,maxCount)
Returns the given range of objects from the result set
sort sort(<+|-><property)
Sorts by the given property in order specified by the prefix (+ for ascending, - for descending)
Filtering
eq eq(<property>,<value>)
Filters for objects where the specified property's value is equal to the provided value
ne ne(<property>,<value>)
Filters for objects where the specified property's value is not equal to the provided value
lt lt(<property>,<value>)
Filters for objects where the specified property's value is less than the provided value
le le(<property>,<value>)
Filters for objects where the specified property's value is less than or equal to the provided value
gt gt(<property>,<value>)
Filters for objects where the specified property's value is greater than the provided value
ge ge(<property>,<value>)
Filters for objects where the specified property's value is greater than or equal to the provided value
in in(<property>,<array-of-values>)
Filters for objects where the specified property's value is not in the provided array
out out(<property>,<array-of-values>)
Filters for objects where the specified property's value is an array and the array
contains contains(<property>,<value | expression>)
Filters for objects where the specified property's value is an array and the array contains any value that equals the provided value or satisfies the provided expression.
excludes excludes(<property>,<value | expression>)
Filters for objects where the specified property's value is an array and the array does not contain any of value that equals the provided value or satisfies the provided expression.
rel rel(<relation name?>,<query>)
Applies the provided query against the linked data of the provided relation name.
and and(<query>,<query>,...)
Applies all the given queries
or or(<query>,<query>,...)
The union of the given queries
Aggregating
aggregate aggregate(<property|function>,...)
Aggregates the array, grouping by objects that are distinct for the provided properties, and then reduces the remaining other property values using the provided functions
sum sum(<property?>)
Finds the sum of every value in the array or if the property argument is provided, returns the sum of the value of property for every object in the array
mean mean(<property?>)
Finds the mean of every value in the array or if the property argument is provided, returns the mean of the value of property for every object in the array
max max(<property?>)
Finds the maximum of every value in the array or if the property argument is provided, returns the maximum of the value of property for every object in the array
min min(<property?>)
Finds the minimum of every value in the array or if the property argument is provided, returns the minimum of the value of property for every object in the array
count count()
Returns the count of the number of records in the query's result set
Misc
Nested properties
Any property can be nested by using an array of properties. To search by the bar property of the object in the foo property we can do: (foo,bar)=3 shorthand: foo/bar=3
Typed values
foo=string:3
recurse recurse(<property?>)
Recursively searches, looking in children of the object as objects in arrays in the given property value
first first()
Returns the first record of the query's result set
one one()
Returns the first and only record of the query's result set, or produces an error if the query's result set has more or less than one record in it.

Compatibility Matrix

JS Array MongoDB SQL Elastic Search
Queries
select meta: {"fields":{"a":1,"b":2}} SELECT property1, property2 {"fields" : ["user", "postDate"]}
values not working not implemented not implemented
distinct not implemented not implemented, probably will work only for one specified key (docs) SELECT DISTINCT maybe facets could do it
limit meta : {"skip": start,"limit": count,"needCount":true} LIMIT start, count {"from": start, "size": count}
sort meta: {"sort":{"a":1,"b":-2}} ORDER BY property1 DESC, property2 ASC [ { "post_date" : {"order" : "asc"} }, "user", { "name" : "desc" }, { "age" : "desc" }, "_score" ]
Filtering
eq direct value = filter term
ne $ne != <> filter not term
lt $lt < filter range lt
le $lte <= filter range le
gt $gt > filter range gt
ge $gte >= filter range ge
in $in WHERE property IN(val1,val2,...) query bool should
out $nin WHERE property NOT IN(val1,val2,...) filter not query bool should
contains $all arrays not supported
excludes $nor $all arrays not supported
rel
and bugs
$and
AND buggy
filter and
or bugs
$or
OR buggy
filter or
Aggregating
aggregate
sum
mean
max
min
count
Misc
Nested properties not supported
Typed values
recurse
first
one
Key
supported and tested partially supported not supported unknown, not tested

Resources

RQL

draft of specification
github and docs

MongoDB

docs querying
SQL to Mongo mapping chart

SQL

docss select
docs expressions
docs operators
docs functions

Elastic Search

docs query DSL
docs API search

Misc

Data Query Protocol

Created by: Jakub Dundalek
Some texts and examples taken from RQL docs created by Kris Zyp
Last updated: 1.8.2012