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

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

Show execution results

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

Hide execution results

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

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

Show execution results

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

Hide execution results

Ignore any limit with count:

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

Show execution results

  1. null

Hide execution results

Counting any limit or skip:

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

Show execution results

  1. null

Hide execution results