Data Subscriptions: Creation API Overview

Create and CreateForRevisions overloads summary

Subscription creation is accessible through DocumentStore's subscriptions() method, of type DocumentSubscriptions:

String create(SubscriptionCreationOptions options);

String create(SubscriptionCreationOptions options, String database);

<T> String create(Class<T> clazz);

<T> String create(Class<T> clazz, SubscriptionCreationOptions options);

<T> String create(Class<T> clazz, SubscriptionCreationOptions options, String database);

<T> String createForRevisions(Class<T> clazz);

<T> String createForRevisions(Class<T> clazz, SubscriptionCreationOptions options);

<T> String createForRevisions(Class<T> clazz, SubscriptionCreationOptions options, String database);
clazz Class Subscription item class
options SubscriptionCreationOptions Contains subscription creation options
database String Name of database to create a data subscription. If null, default database configured in DocumentStore will be used.
Return value
String Created data subscription name. If Name was provided in SubscriptionCreationOptions, it will be returned, otherwise, a unique name will be generated by server.


Non generic version of the class, relies on user's full knowledge of the RQL query structure

Member Type Description
name String User defined name of the subscription: allows to have a human readable identification of a subscription. The name must be unique in the database.
query String Required. RQL query that describes the subscription. That RQL comes with additional support to javascript clause inside the 'Where' statement and special semantics for subscriptions on documents revisions.
changeVector String Allows to define a change vector, from which the subscription will start processing. It might be useful for ad-hoc processes that need to process only recent changes in data, for that specific use, the field may receive a special value: "LastDocument", that will take the latest change vector in the machine.
mentorNode String Allows to define a specific node in the cluster that we want to treat the subscription. That's useful in cases when one server is preffered over other, either because of stronger hardware or closer geographic proximity to clients etc.

Subscription query

  • Functions definition part, like in ordinary RQL. Those functions can contain any javascript code, and also supports load and include operations.

  • From statement, defining the documents source, ex: from Orders. The from statement can only address collections, therefore, indexes are not supported.

  • Where statement describing the criteria according to which it will be decided to either send the documents to the worker or not. Those statements supports either RQL like equality operations (=, ==) ,
    plain JavaScript expressions or declared function calls, allowing to perform complex filtering logic.
    The subscriptions RQL does not support any of the known RQL searching keywords.

  • Select statement, that defines the projection to be performed. The select statements can contain function calls, allowing complex transformations.

  • Include statement allowing to define include path in document.


Although subscription's query syntax has an RQL-like structure, it supports only the declare, select and where keywords, usage of all other RQL keywords is not supported.
Usage of JavaScript ES5 syntax is supported.


Paths in subscriptions RQL statements are treated as Javascript indirections and not like regular RQL paths.
It means that a query that in RQL would look like:

from Orders as o
where o.Lines[].Product = "products/1-A"

Will look like that in subscriptions RQL:

declare function filterLines(doc, productId)
    if (!!doc.Lines){
        return doc.Lines.filter(x=>x.Product == productId).length >0;
    return false;

from Orders as o
where filterLines(o, "products/1-A")


In order to define a data subscription that uses documents revisions, there first has to be revisions configured for the specific collection.
The subscription should be defined in a special way:
* In case of the generic API, use method 'createForRevisions' instead of 'create'
* For RQL syntax, the (Revisions = true) statement should be concatenated to the collection to be queries. Ex: From orders(Revisions = true) as o