Reputation: 319
Say that my firebase data structure looks like this picture below:
I am trying to query the clients based on the customerNumber
within settings
.
My most recent attempt, I've tried the following:
var number = register.number;
var ref = new Firebase(fbUrl+'/clients/');
ref.orderByChild("settings").orderByChild("customerNumber").equalTo(number).on("child_added", function(snapshot) {
console.log(snapshot.key());
});
but apparently you can't use two orderByChild()
functions.
So how would I do this? I've built this project way too much to change my structure now so that is NOT an option or a solution that is possible at this point.
I want to return the entire parents based on the customerNumber
matching within the settings of the parent data structure.
Upvotes: 1
Views: 1662
Reputation: 598728
I'm not sure why the comment I left doesn't work for you. Here is the snippet I just used to reproduce it:
var ref = new Firebase('https://mine.firebaseio.com');
ref.child('clients')
.orderByChild('settings/customerNumber')
.equalTo('1234567890')
.once('value', function(snapshot) {
console.log(snapshot.val());
});
See this jsbin: http://jsbin.com/towewegapa/edit?js,console
Upvotes: 1
Reputation: 402
You should 'Prefer Flattened Data' as Firebase ask us to do in their documentation : structuring data in firebase
You could maintain a second index that map the custumerNumber with the Firebasekey in clients
Upvotes: 0