order by timestamp asc

2,036 views
Skip to first unread message

kevin

unread,
Dec 5, 2014, 11:25:35 AM12/5/14
to fireba...@googlegroups.com

I am trying to figure out how to order my data by timestamp ASC or DEC.  My timestamp key is called dayStamp.  Here is my code to pull the data


 var fb = new Firebase('https://sizzling-fire-###.firebaseio.com/mytimes')
               
.startAt(1417743634)
               
.endAt(1417747128);
        fb
.once('value', function(snap) {
            snap
.forEach(function(ss) {
               
var dbFire=ss.val();


           
});

       
});


Jacob Wenger

unread,
Dec 5, 2014, 12:57:19 PM12/5/14
to fireba...@googlegroups.com
Hey Kevin,

We recently released new querying capabilities with version 2.0.x of Firebase. So make sure you have upgraded to the latest version (2.0.6 as of this comment). I'd start by looking at the docs for our new querying capabilities.

Once you've read that, you can use the new orderByChild() method to sort by your dayStamp key:

// Create Firebase ref

// Create new query
var query = ref.orderByChild('dayStamp')
   .startAt(1417743634)
   .endAt(1417747128);

// Get results in ascending (result) and descending (reverseResults) order
query.once('value', function(snap) {
  var results = [];
  snap.forEach(function(ss) {
    results.push(ss.val());
  });
  
  var reverseResults = results.reverse();
});

Jacob

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/c212aa42-cdec-4709-a691-253c3ec8fc59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages