Reverse
Reverse( source )
Returns
When source
is an Array, an array containing the items found in
source
, with their original order reversed.
When source
is a Set, a set containing the items found in source
,
with their original order reversed.
When source
is a Page, a page of the items found in source
, with
their original order reversed.
Examples
-
The following query passes an array to
Reverse
:Copied!client.query( q.Reverse(["a", "b", "c", 1, 2, 3]) ) .then((ret) => console.log(ret)) .catch((err) => console.log('Error:', err))
[ 3, 2, 1, 'c', 'b', 'a' ]
-
The following query reverses the set of documents in the
Letters
collection (established in the Indexing tutorial, and then paginates the set:Copied!client.query( q.Paginate(q.Reverse(q.Documents(q.Collection("Letters")))) ) .then((ret) => console.log(ret)) .catch((err) => console.log('Error:', err))
{ data: [ Ref(Collection("Letters"), "126"), Ref(Collection("Letters"), "125"), Ref(Collection("Letters"), "124"), Ref(Collection("Letters"), "123"), Ref(Collection("Letters"), "122"), Ref(Collection("Letters"), "121"), Ref(Collection("Letters"), "120"), Ref(Collection("Letters"), "119"), Ref(Collection("Letters"), "118"), Ref(Collection("Letters"), "117"), Ref(Collection("Letters"), "116"), Ref(Collection("Letters"), "115"), Ref(Collection("Letters"), "114"), Ref(Collection("Letters"), "113"), Ref(Collection("Letters"), "112"), Ref(Collection("Letters"), "111"), Ref(Collection("Letters"), "110"), Ref(Collection("Letters"), "109"), Ref(Collection("Letters"), "108"), Ref(Collection("Letters"), "107"), Ref(Collection("Letters"), "106"), Ref(Collection("Letters"), "105"), Ref(Collection("Letters"), "104"), Ref(Collection("Letters"), "103"), Ref(Collection("Letters"), "102"), Ref(Collection("Letters"), "101") ] }
-
The following query reverses the page of results from paginating the documents in the
Letters
collection:Copied!client.query( q.Reverse( q.Paginate( q.Documents(q.Collection("Letters")), { size: 3, after: q.Ref(q.Collection("Letters"), "104") } ) ) ) .then((ret) => console.log(ret)) .catch((err) => console.log('Error:', err))
{ before: [ Ref(Collection("Letters"), "104") ], after: [ Ref(Collection("Letters"), "107") ], data: [ Ref(Collection("Letters"), "106"), Ref(Collection("Letters"), "105"), Ref(Collection("Letters"), "104") ] }
Notice that
Reverse
has reversed the order of the results in the page, but has not affected the pagination order.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!