1
0
Fork 0
arangodb/Documentation/Books/Manual/appendix-deprecated-simple-...

130 lines
4.3 KiB
Markdown

---
layout: default
description: Simple Queries Pagination (Deprecated)
---
Pagination
==========
{% hint 'warning' %}
It is recommended to use AQL instead, see the [**LIMIT operation**](aql/operations-limit.html).
{% endhint %}
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 *n*th page. This result
should be sorted, so that the pagination works in a predicable way.
Limit
-----
<!-- js/common/modules/@arangodb/simple-query-common.js -->
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**
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
@startDocuBlockInline queryLimit
@EXAMPLE_ARANGOSH_OUTPUT{queryLimit}
~ db._create("five");
~ db.five.save({ name : "one" });
~ db.five.save({ name : "two" });
~ db.five.save({ name : "three" });
~ db.five.save({ name : "four" });
~ db.five.save({ name : "five" });
db.five.all().toArray();
db.five.all().limit(2).toArray();
~ db._drop("five")
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock queryLimit
{% endarangoshexample %}
{% include arangoshexample.html id=examplevar script=script result=result %}
Skip
----
<!-- js/common/modules/@arangodb/simple-query-common.js -->
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**
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
@startDocuBlockInline querySkip
@EXAMPLE_ARANGOSH_OUTPUT{querySkip}
~ db._create("five");
~ db.five.save({ name : "one" });
~ db.five.save({ name : "two" });
~ db.five.save({ name : "three" });
~ db.five.save({ name : "four" });
~ db.five.save({ name : "five" });
db.five.all().toArray();
db.five.all().skip(3).toArray();
~ db._drop("five")
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock querySkip
{% endarangoshexample %}
{% include arangoshexample.html id=examplevar script=script result=result %}
Ignore any limit with count:
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
@startDocuBlockInline cursorCountUnLimited
@EXAMPLE_ARANGOSH_OUTPUT{cursorCountUnLimited}
~ db._create("five");
~ db.five.save({ name : "one" });
~ db.five.save({ name : "two" });
~ db.five.save({ name : "three" });
~ db.five.save({ name : "four" });
~ db.five.save({ name : "five" });
db.five.all().limit(2).count();
~ db._drop("five")
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock cursorCountUnLimited
{% endarangoshexample %}
{% include arangoshexample.html id=examplevar script=script result=result %}
Counting any limit or skip:
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
@startDocuBlockInline cursorCountLimit
@EXAMPLE_ARANGOSH_OUTPUT{cursorCountLimit}
~ db._create("five");
~ db.five.save({ name : "one" });
~ db.five.save({ name : "two" });
~ db.five.save({ name : "three" });
~ db.five.save({ name : "four" });
~ db.five.save({ name : "five" });
db.five.all().limit(2).count(true);
~ db._drop("five")
@END_EXAMPLE_ARANGOSH_OUTPUT
@endDocuBlock cursorCountLimit
{% endarangoshexample %}
{% include arangoshexample.html id=examplevar script=script result=result %}