Returned records shows in reverse order even after using 'orderByKey()' and even with 'limitToFirst()'
Issue
I'm developing a game with React Native & Firebase. I have changed the setup today to use React-Native-Firebase instead of Firebase for Web.
import firebase from 'react-native-firebase'
After the changes I have noticed that data are displaying in reverse order.
e.g. const tournamentsData = firebase.database().ref('/Game/Tournaments')
which earlier retrieved the tournaments array as [{Avengers: {...}}, {TomAndJerry: {...}}]
but now it's coming as [{TomAndJerry: {...}}, {Avengers: {...}}]
I tried to use 'orderByKey()' then combined with 'limitToFirst(2)' then I tried "orderByChild('index')" but always result comes as same reverse order. When I check Objects within above objects are also received in reverse order
When I changed back to use firebase for web, everything back to correct order without any query changes.
i.e. import firebase from 'firebase'
Environment
-
Application Target Platform: Android 6 and above
-
Development Operating System: Windows 8
-
Build Tools: Android Studio 3.0.1 / Android SDK 25
- React Native version: 0.50.4
- RNFirebase Version: 11.6.2
Hello thanks for the report. Could we see your code usage around making the database call.
Hi Ehesp,
Please find it below. let me know if you need further information.
const tournamentsData = firebase.database().ref('/Game/Tournaments').orderByKey().limitToFirst(3)
tournamentsData.once('value')
.then((snapshot) => {
if(snapshot.val()) {
dispatch({
type: TOURNAMENT_DATA_LOADED,
payload: snapshot.val()
})
} else {
dispatch({
type: TOURNAMENT_DATA_LOADING_ERROR,
})
}
})
@weerakkodylr how are you iterating over the returned payload out of interest? Firebase doesn't always give the data back in the order it is stored - a snapshot.forEach method is available to do this... Are you using it?
@Ehesp , thanks for looking in to this.
Actually Firebase does return the data in the same order always (for me). The time I spent with firebase DB (past 6 months with web version in React Native) and this ordering issue didn't happen even a single time. firebase for Web always return the order I requested in the query and I didn't want to do additional ordering in the app.
And the other thing is then there is no use of 'orderByKey()' , 'orderByValue()'
I can ignore this issue by doing the ordering on the snapshot or inside the reducer but since I always receives the data from firebase as I expected, I believe this is some kind of an issue in the react-native-firebase and it should be fixed.
Thanks again for spending time on my request :)
This issue has been automatically marked as stale because it has not had recent user activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.
I'm having the similar issue. Not sure if anyone has already found a solution.
I'm noticing this as well, adding orderByKey doesn't do anything. I wonder if this should be reopened?