First of all, thanks for this great project!
I have this issue with orderByChild
which is not working as expected.
firebase.database().ref(`/users/${userUid}/items`)
.orderByChild('priority')
.once('value', snapshot => {
// doesn't sort
});
similar to this issue from react-native-firestack
https://github.com/fullstackreact/react-native-firestack/issues/82
Anyone else with the same issue?
Hey, when you say doesn't work in the callback, does it simply not get there or something else?
The returned result is not in proper order.
Are you iterating over the results using snapshot.forEach?
I am using a lodash map on the result. But the snapshot.val()
is not in order even before the _.map
Please see: https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot#forEach
Because of the way JavaScript objects work, the ordering of data in the JavaScript object returned by val() is not guaranteed to match the ordering on the server nor the ordering of child_added events. That is where forEach() comes in handy. It guarantees the children of a DataSnapshot will be iterated in their query order.
That's good to know. Let me look into that. Thanks!
Closing for now, let me know if you have anymore problems with the above taken into account.
@Ehesp I tried what you pointing towards and it is give error;
getDates() {
firebase.database().ref('dates').orderByKey().once('value').then(
(snapshot) => {
snapshot.forEach(date => {
let dt = date.snapshot()
this.dates.push(dt);
});
console.log(this.dates);
}
)
}
TypeError: snapshot.forEach is not a function
I am using Angular+NativeScript.
Most helpful comment
Please see: https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot#forEach