order()
Lazy loading: |
Description
The order()
method takes one or more Ordering
objects to sort
a Set. An Ordering object is created by using the asc()
or
desc()
function with a field accessor:
-
asc()
: sort by the field in ascending order -
desc()
: sort by the field in descending order
The first ordering parameter has the highest sorting priority and priority decreases with each subsequent parameter.
If order()
is the last value in a query, the first page of the new
Set is returned.
The source set isn’t changed.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
ordering |
Ordering[] |
Ordering to apply to Set values. One or more Ordering objects. ordering objects: |
Examples
Sort the People documents by last name, in default ascending order:
{
data: [
{
first: "Stephen",
last: "Cook",
age: 83
},
{
first: "Tim",
last: "Cook",
age: 62
},
{
first: "Grace",
last: "Hopper",
age: 116
},
{
first: "Leslie",
last: "Lamport",
age: 81
},
{
first: "Marvin",
last: "Minsky",
age: 95
},
{
first: "Alan",
last: "Perlis",
age: 100
},
{
first: "Alan",
last: "Turing",
age: 110
}
]
}
Sort the People documents by age, in descending order:
{
data: [
{
first: "Grace",
last: "Hopper",
age: 116
},
{
first: "Alan",
last: "Turing",
age: 110
},
{
first: "Alan",
last: "Perlis",
age: 100
},
{
first: "Marvin",
last: "Minsky",
age: 95
},
{
first: "Stephen",
last: "Cook",
age: 83
},
{
first: "Leslie",
last: "Lamport",
age: 81
},
{
first: "Tim",
last: "Cook",
age: 62
}
]
}
Sort the People documents by last name and age, in default ascending order of last name and age, projecting first name, last name, and age:
{
data: [
{
first: "Tim",
last: "Cook",
age: 62
},
{
first: "Stephen",
last: "Cook",
age: 83
},
{
first: "Grace",
last: "Hopper",
age: 116
},
{
first: "Leslie",
last: "Lamport",
age: 81
},
{
first: "Marvin",
last: "Minsky",
age: 95
},
{
first: "Alan",
last: "Perlis",
age: 100
},
{
first: "Alan",
last: "Turing",
age: 110
}
]
}
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!