Here we create a subscription on Orders collection, which returns the orders and brings along all products mentioned in the order as included documents.
See the usage example here.
Include statements can be added to a subscription in the raw RQL, or with the
The subscription include builder is assigned to the option Includes in
(see subscription API overview). It
supports methods for including documents. These methods can be chained.
In raw RQL, include statements come in two forms, like in any other RQL statements:
1. Include statement in the end of the query, starting with the
include keyword, followed by paths to the field containing the ids of the documents to include.
If projection is performed, the mechanism will look for the paths in the projected result, rather then the original document.
It is recommended to prefer this approach when possible both because of clarity of the query and slightly better performance.
2. Include function call inside a 'declared' function.
Includes = builder => builder
.IncludeDocuments(x => x.Lines.Select(y => y.Product))
Query = @"from Orders include Lines.Product"
Query = @"
declare function includeProducts(doc)
doc.LinesCount = doc.Lines.length;
for (let i=0; i< doc.Lines.length; i++)
from Orders as o select includeProducts(o)"