i am facing problems with understanding more about on and once in firebase API.
Assume I have this DB structure
When I listen for child_added, it works as expected.
firebase.database().ref(this.getRootRef())
.orderByChild('createdAt')
.limitToLast(NUM_MSG_PER_REQUEST)
.on('child_added', (datas) => {
if (datas) {
_callback(datas.val());
}
});
But when I would to filter with once, nothing effected.
firebase.database().ref(this.getRootRef())
.orderByChild('createdAt')
.endAt('createdAt', '2019-03-17 02:46:50') // tested with startAt, equalsTo => the same result. No effect
// .limitToLast(NUM_MSG_PER_REQUEST)
.once('value', (vals) => {console.log(vals.val()});
Could someone explain more about these 2 functions and in this case, what should I write my could to have filters when doing once ?
Thanks a lot!
Update on 03/18/2019
The function getRootRef() returns '/messages/2019-03-15'.
Both code snippet work, but what I am not clear here is how the filters applied.
For example: orderByChild('createdAt')
With this filter, the first one return results which are ordered by 'createdAt'. But the second one will not. It return with no order.