I'm looking into implementing an in-firebase index as described here: https://stackoverflow.com/a/10559689/534086, and trying to figure out how to deal with sorting data in descending order. Is it possible if you have a node with children 'a', 'b', 'c' to retrieve them 'c', 'b', 'a'? (while still being able to retrieve them in the original order as well?)
If it's not possible to traverse the node both forwards and backwards and I need to create two indexes, is their an easy algorithm for generating keys that sort in reverse lexographic order? For numbers, I think you can multiply by -1, but not sure how to handle strings...
Use the push() method to append data to a list in multiuser applications. The push() method generates a unique key every time a new child is added to the specified Firebase reference.
We could create this data by sending the following JSON tree to the player's collection. This is because Firebase does not support Arrays directly, but it creates a list of objects with integers as key names.
Asynchronous listeners: Data stored in a Firebase Realtime Database is retrieved by attaching an asynchronous listener to a database reference. The listener is triggered once for the initial state of the data and again anytime the data changes.
It sounds like what you want is a "reverse()" query similar to how "limit()" works now. Firebase can't do this yet, but we're planning to add it.
Depending on your use case, it might be pretty simple for you to get around this though. If, for instance, you're using Firebase's sorting to keep a list in order that is being displayed to the user, you could simply modify the display logic to render things backward (prepend items instead of append for instance). If you're querying to select a window of data out of a large set of children (say, to get the first 10 items out of a long list), the sort order shouldn't be important -- your start and end points for the query will remain the same except they'll be reversed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With