You're viewing the legacy docs. They are deprecated as of May 18, 2016.
These docs are for version 2.4.2 and below of the Javascript SDK. Go to our current docs, or see our Web migration guide.

Version 2.4.2Changelog


We can order nodes by a child key that they all share by passing that key to orderByChild(). For example, using our sample database of dinosaur facts, we can read all dinosaurs ordered by height using the following query:

var ref = new Firebase("");
ref.orderByChild("height").on("child_added", function(snapshot) {
  console.log(snapshot.key() + " was " + snapshot.val().height + " meters tall");

Queries can currently only order by one key at a time. Calling orderByChild() multiple times on the same query throws an error.

Using Indexes For Improved Performance

Firebase queries allow you to order your data by any child key, on the fly. However, if you know in advance what your indexes will be, you can define them via the .indexOn rule in your Security and Firebase Rules for better performance. Read the documentation on the .indexOn rule for more information.

You can read more about orderByChild() in our ordering data documentation.