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 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

  1. arangosh> db.five.all().toArray();
  2. arangosh> db.five.all().limit(2).toArray();

Show execution results

Hide execution results

  1. [
  2. {
  3. "_key" : "91765",
  4. "_id" : "five/91765",
  5. "_rev" : "_dAzP4Y6---",
  6. "name" : "one"
  7. },
  8. {
  9. "_key" : "91767",
  10. "_id" : "five/91767",
  11. "_rev" : "_dAzP4Y6--A",
  12. "name" : "two"
  13. },
  14. {
  15. "_key" : "91769",
  16. "_id" : "five/91769",
  17. "_rev" : "_dAzP4Z----",
  18. "name" : "three"
  19. },
  20. {
  21. "_key" : "91771",
  22. "_id" : "five/91771",
  23. "_rev" : "_dAzP4Z---A",
  24. "name" : "four"
  25. },
  26. {
  27. "_key" : "91773",
  28. "_id" : "five/91773",
  29. "_rev" : "_dAzP4ZC---",
  30. "name" : "five"
  31. }
  32. ]
  33. [
  34. {
  35. "_key" : "91765",
  36. "_id" : "five/91765",
  37. "_rev" : "_dAzP4Y6---",
  38. "name" : "one"
  39. },
  40. {
  41. "_key" : "91767",
  42. "_id" : "five/91767",
  43. "_rev" : "_dAzP4Y6--A",
  44. "name" : "two"
  45. }
  46. ]

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

  1. arangosh> db.five.all().toArray();
  2. arangosh> db.five.all().skip(3).toArray();

Show execution results

Hide execution results

  1. [
  2. {
  3. "_key" : "91788",
  4. "_id" : "five/91788",
  5. "_rev" : "_dAzP4Zi---",
  6. "name" : "one"
  7. },
  8. {
  9. "_key" : "91790",
  10. "_id" : "five/91790",
  11. "_rev" : "_dAzP4Zm---",
  12. "name" : "two"
  13. },
  14. {
  15. "_key" : "91792",
  16. "_id" : "five/91792",
  17. "_rev" : "_dAzP4Zm--A",
  18. "name" : "three"
  19. },
  20. {
  21. "_key" : "91794",
  22. "_id" : "five/91794",
  23. "_rev" : "_dAzP4Zq---",
  24. "name" : "four"
  25. },
  26. {
  27. "_key" : "91796",
  28. "_id" : "five/91796",
  29. "_rev" : "_dAzP4Zq--A",
  30. "name" : "five"
  31. }
  32. ]
  33. [
  34. {
  35. "_key" : "91794",
  36. "_id" : "five/91794",
  37. "_rev" : "_dAzP4Zq---",
  38. "name" : "four"
  39. },
  40. {
  41. "_key" : "91796",
  42. "_id" : "five/91796",
  43. "_rev" : "_dAzP4Zq--A",
  44. "name" : "five"
  45. }
  46. ]

Ignore any limit with count:

  1. arangosh> db.five.all().limit(2).count();

Show execution results

Hide execution results

  1. null

Counting any limit or skip:

  1. arangosh> db.five.all().limit(2).count(true);

Show execution results

Hide execution results

  1. null