I\'m trying to order by timestamp in Firebase using orderByChild()
but it\'s not working. The results seem to be ordered by the key and Firebase seems to be ign
Works for me:
firebase.database().ref(endpoint)
.orderByChild('timestamp')
.on('value', function(snapshot) {
this.data = [];
snapshot.forEach(function(child) {
this.data.push(child.val());
}.bind(this));
console.log("all", data.map(function(val) { return new Date(val.timestamp).toString(); }));
});
"all"
["Fri Jun 17 2016 06:51:33 GMT-0700 (PDT)", "Fri Jun 17 2016 06:51:37 GMT-0700 (PDT)", "Fri Jun 17 2016 06:51:38 GMT-0700 (PDT)", "Fri Jun 17 2016 06:51:43 GMT-0700 (PDT)"] Blockquote
firebase.database().ref(endpoint)
.orderByChild('timestamp')
.startAt(1466171497190)
.endAt(1466171498405)
.on('value', function(snapshot) {
this.data = [];
snapshot.forEach(function(child) {
this.data.push(child.val());
}.bind(this));
console.log("filtered", data.map(function(val) { return new Date(val.timestamp).toString(); }));
});
"filtered"
["Fri Jun 17 2016 06:51:37 GMT-0700 (PDT)", "Fri Jun 17 2016 06:51:38 GMT-0700 (PDT)"]
http://jsbin.com/humatuquju/edit?js,console