Pagination
It is recommended to use AQL instead, see the LIMIT operation.
If, for example, you display the result of a user search, then you are ingeneral not interested in the completed result set, but only the first 10 or sodocuments. Or maybe the next 10 documents for the second page. In this case, youcan the skip and limit operators. These operators work like LIMIT inMySQL.
skip used together with limit can be used to implement pagination.The skip operator skips over the first n documents. So, in order to createresult pages with 10 result documents per page, you can useskip(n * 10).limit(10)
to access the 10 documents on the _n_th page. This resultshould be sorted, so that the pagination works in a predicable way.
Limit
limitquery.limit(number)
Limits a result to the first number documents. Specifying a limit of0 will return no documents at all. If you do not need a limit, just donot add the limit operator. The limit must be non-negative.
In general the input to limit should be sorted. Otherwise it will beunclear which documents will be included in the result set.
Examples
- arangosh> db.five.all().toArray();
- arangosh> db.five.all().limit(2).toArray();
Show execution results
Hide execution results
- [
- {
- "_key" : "88600",
- "_id" : "five/88600",
- "_rev" : "_Z2KDUS6---",
- "name" : "one"
- },
- {
- "_key" : "88602",
- "_id" : "five/88602",
- "_rev" : "_Z2KDUS6--A",
- "name" : "two"
- },
- {
- "_key" : "88604",
- "_id" : "five/88604",
- "_rev" : "_Z2KDUT----",
- "name" : "three"
- },
- {
- "_key" : "88606",
- "_id" : "five/88606",
- "_rev" : "_Z2KDUT---A",
- "name" : "four"
- },
- {
- "_key" : "88608",
- "_id" : "five/88608",
- "_rev" : "_Z2KDUTC---",
- "name" : "five"
- }
- ]
- [
- {
- "_key" : "88600",
- "_id" : "five/88600",
- "_rev" : "_Z2KDUS6---",
- "name" : "one"
- },
- {
- "_key" : "88602",
- "_id" : "five/88602",
- "_rev" : "_Z2KDUS6--A",
- "name" : "two"
- }
- ]
Skip
skipquery.skip(number)
Skips the first number documents. If number is positive, then thisnumber of documents are skipped before returning the query results.
In general the input to skip should be sorted. Otherwise it will beunclear 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();
- arangosh> db.five.all().skip(3).toArray();
Show execution results
Hide execution results
- [
- {
- "_key" : "88621",
- "_id" : "five/88621",
- "_rev" : "_Z2KDUTe--A",
- "name" : "one"
- },
- {
- "_key" : "88623",
- "_id" : "five/88623",
- "_rev" : "_Z2KDUTi---",
- "name" : "two"
- },
- {
- "_key" : "88625",
- "_id" : "five/88625",
- "_rev" : "_Z2KDUTi--A",
- "name" : "three"
- },
- {
- "_key" : "88627",
- "_id" : "five/88627",
- "_rev" : "_Z2KDUTm---",
- "name" : "four"
- },
- {
- "_key" : "88629",
- "_id" : "five/88629",
- "_rev" : "_Z2KDUTm--A",
- "name" : "five"
- }
- ]
- [
- {
- "_key" : "88627",
- "_id" : "five/88627",
- "_rev" : "_Z2KDUTm---",
- "name" : "four"
- },
- {
- "_key" : "88629",
- "_id" : "five/88629",
- "_rev" : "_Z2KDUTm--A",
- "name" : "five"
- }
- ]
Ignore any limit with count:
- arangosh> db.five.all().limit(2).count();
Show execution results
Hide execution results
- null
Counting any limit or skip:
- arangosh> db.five.all().limit(2).count(true);
Show execution results
Hide execution results
- null