From everything that I read, it is not possible to request a multilevel value. My data structure is as follows:
{ "dinosaurs": { "bruhathkayosaurus": { "meta":{ "addedBy":"John", "addedDate":"02021987" }, "appeared": -70000000, "height": 25 }, "lambeosaurus": { "meta":{ "addedBy":"Peter", "addedDate":"12041987" }, "appeared": -76000000, "height": 2.1 } } }
Without knowing the name of the dinosaur key, you still need to request the meta node to receive only elements added by John.
In JS Something like:
var ref = new Firebase('test.firebaseio.com/dinosaurs'); ref.orderByChild("meta/addedBy") .equalTo('Peter') .on("child_added", function(snapshot) { console.log(snapshot); });
There are hacker solutions, but none of them scale, should I just smooth out this data?
Edit:
I need a code review ... would this be an acceptable solution?
var ref = new Firebase('test.firebaseio.com/dinosaurs'); ref.orderByChild("meta") .on('child_added',function(snap1){ snap1.ref().orderByChild("addedBy") .equalTo("Peter") .on('child_added', function(snap2) { console.log(snap2.val()); }) });
firebase
dmo
source share