1

I've been scratching my head and trying to figure out how to query using firebase's "orderByChild" with a slightly deeper nested data structure than as shown in the example docs.

I might be just missing something simple here, but I can't seem to find any solutions, so I'd appreciate some help.

So, my data is structured like so:

    users {
      "-Jlg6b7GoQVDALQAV_5s" : {
        "email" : "peter@emailaddress.com",
        "name" : {
          "first" : "Peter",
          "last" : "Griffin"
        }
      },
      "-Jlg7BhzUfMO79mpP0_K" : {
        "email" : "louis@emailaddress.com",
        "name" : {
          "first" : "Louis",
          "last" : "Griffin"
        }
      },
      "-Jlg8Ym0LEXgkkT_r0p1" : {
        "email" : "brian@emailaddress.com",
        "name" : {
          "first" : "Brian",
          "last" : "Griffin"
        }
      }
    }

If I use "orderByChild" on the email address, the result is correct:

var ref = new Firebase("https://xxxxxxxxx.firebaseio.com/users");
ref.orderByChild('email').on('child_added', function (snapshot) {
  console.log(snapshot.key(), snapshot.val().name.first);
});

But how can I query the users nested name.first property to return the users in order by first name?

Thanks!

David Rees
  • 11
  • 1
  • 1
    Firebase indexes only work one level deep at the moment. So in your example you *can* order/filter your users on `email`, but *not* on `name/first`. – Frank van Puffelen Apr 01 '15 at 16:40

0 Answers0