firebase select count for 1 day -


so lets have few of data on 1 day , set of data on day. these data store in same table. there way me select count each day: lets day 1 has 20 counts , day 2 has 13 counts?enter image description here

the easiest way add child object. call date , save date yyyymmdd. gives date stamp on each object.

then can query like;

firebase.database()   .ref('/button_log')   .orderbychild('date')   .equalto('20170818')    .once('value')    .then(snapshot => {      console.log(snapshot.numchildren());   // number of records    }); 

otherwise if don't want new child, try like;

firebase.database()   .ref('/button_log')   .orderbychild('time')   .startat('2017-08-10')   .endat('2017-08-10 23:59:59')   .once('value')   .then(snapshot => {     console.log(snapshot.numchildren());  // number of records   }); 

edit

thomas has suggested use unix timestamp it's more flexible.

when savings data set created timestamp firebase.database.servervalue.timestamp save timestamp.

then can query like;

var startofday = new date(); startofday.sethours(0,0,0,0);  var endofday = new date(); endofday.sethours(23,59,59,999);  firebase.database()   .ref('/button_log')   .orderbychild('timestamp')   .startat(startofday)   .endat(endofday)   .once('value')   .then(snapshot => {     console.log(snapshot.numchildren()); // number of records   }); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -