Default ordering
By default, children are sorted by their key. This is the order you get when you read a path without specifying any ordering.Ordering modes
Lark supports four ordering modes. You pick one per query.Order by key
Sorts children by their key name. Keys that are valid 32-bit integers are sorted numerically first, then remaining string keys are sorted lexicographically.Order by value
Sorts children by their value directly. This works when the children are primitive values (strings, numbers, booleans), not objects.Order by child
Sorts children by the value of a nested child field. This is the one you’ll use most often.null (which comes first in Lark’s sort order).
Order by priority
Sorts children by their priority metadata. Priority is a legacy ordering mechanism — in most cases,orderByChild is a better choice. But it’s available when you need it.
Value type precedence
When sorting, Lark follows a strict type ordering. If your data contains mixed types, they sort in this order:| Order | Type | Sorting within type |
|---|---|---|
| 1 | null | All nulls are equal |
| 2 | false | — |
| 3 | true | — |
| 4 | Numbers | Ascending numeric order |
| 5 | Strings | Lexicographic (Unicode) order |
| 6 | Objects | Sorted by key |
25 sorts before the value "apple", regardless of what they’d look like alphabetically.
This type ordering matters most when using
orderByValue or orderByChild on data where different children might have different types for the same field. In practice, keep your types consistent and you won’t need to think about this.Limits
Limits let you cap how many results are returned.limitToFirst
Returns the first N results in the current sort order.limitToLast
Returns the last N results in the current sort order.Ranges
Ranges let you filter results to a specific window within the sort order.startAt / endAt (inclusive)
startAt and endAt define inclusive bounds. Only results that fall within the range are returned.
startAfter / endBefore (exclusive)
startAfter and endBefore are the exclusive versions — they exclude the boundary value itself.
Key tiebreaker
When multiple children have the same sort value,startAt, endAt, startAfter, endBefore, and equalTo all accept an optional second parameter — a key — to disambiguate. This is essential for pagination over data with duplicate values.
startAt(250) would include all children with score 250. With the key, Lark skips past alice and starts at the next child with that score (or the next score above it).
equalTo
equalTo matches exactly one value. It’s a shorthand for setting startAt and endAt to the same value.
orderByKey, equalTo works as a direct key lookup:

