Pagination
If, for example, you display the result of a user search, then you are in general not interested in the completed result set, but only the first 10 or so documents. Or maybe the next 10 documents for the second page. In this case, you can the skip and limit operators. These operators work like LIMIT in MySQL.
skip used together with limit can be used to implement pagination. The skip operator skips over the first n documents. So, in order to create result pages with 10 result documents per page, you can use skip(n * 10).limit(10) to access the 10 documents on the nth page. This result should be sorted, so that the pagination works in a predicable way.
Limit
limit
query.limit(number)
Limits a result to the first number documents. Specifying a limit of 0 will return no documents at all. If you do not need a limit, just do not add the limit operator. The limit must be non-negative.
In general the input to limit should be sorted. Otherwise it will be unclear which documents will be included in the result set.
Examples
arangosh> db.five.all().toArray();
[
{
"_key" : "34141",
"_id" : "five/34141",
"_rev" : "_VTxTc8O---",
"name" : "one"
},
{
"_key" : "34154",
"_id" : "five/34154",
"_rev" : "_VTxTc8W---",
"name" : "five"
},
{
"_key" : "34151",
"_id" : "five/34151",
"_rev" : "_VTxTc8S--_",
"name" : "four"
},
{
"_key" : "34148",
"_id" : "five/34148",
"_rev" : "_VTxTc8S---",
"name" : "three"
},
{
"_key" : "34145",
"_id" : "five/34145",
"_rev" : "_VTxTc8O--_",
"name" : "two"
}
]
arangosh> db.five.all().limit(2).toArray();
[
{
"_key" : "34141",
"_id" : "five/34141",
"_rev" : "_VTxTc8O---",
"name" : "one"
},
{
"_key" : "34154",
"_id" : "five/34154",
"_rev" : "_VTxTc8W---",
"name" : "five"
}
]
arangosh> db.five.all().toArray();
arangosh> db.five.all().limit(2).toArray();
Skip
skip
query.skip(number)
Skips the first number documents. If number is positive, then this number of documents are skipped before returning the query results.
In general the input to skip should be sorted. Otherwise it will be unclear which documents will be included in the result set.
Note: using negative skip values is deprecated as of ArangoDB 2.6 and will not be supported in future versions of ArangoDB.
Examples
arangosh> db.five.all().toArray();
[
{
"_key" : "34169",
"_id" : "five/34169",
"_rev" : "_VTxTd-O--A",
"name" : "three"
},
{
"_key" : "34172",
"_id" : "five/34172",
"_rev" : "_VTxTd-O--B",
"name" : "four"
},
{
"_key" : "34175",
"_id" : "five/34175",
"_rev" : "_VTxTd-S---",
"name" : "five"
},
{
"_key" : "34166",
"_id" : "five/34166",
"_rev" : "_VTxTd-O--_",
"name" : "two"
},
{
"_key" : "34162",
"_id" : "five/34162",
"_rev" : "_VTxTd-O---",
"name" : "one"
}
]
arangosh> db.five.all().skip(3).toArray();
[
{
"_key" : "34166",
"_id" : "five/34166",
"_rev" : "_VTxTd-O--_",
"name" : "two"
},
{
"_key" : "34162",
"_id" : "five/34162",
"_rev" : "_VTxTd-O---",
"name" : "one"
}
]
arangosh> db.five.all().toArray();
arangosh> db.five.all().skip(3).toArray();