Firebase query ordering by child not working
Firebase Realtime Database results are always in ascending order. There is no way to get them in descending order from the database, so you will have to reverse the results in your application code.
A simple option for this is to insert each item at the top of the table, instead of appending it to the bottom as you do now:
self.table.insert(video, at: 0)
The alternative would be to store inverted values in your database, like: userTime: -1654342137807
. That way the ascending order that the database uses, will actually be what you want.
Also see:
- How to get data from firebase in descending order of value?
- Swift - How to create Sort query as Descending on Firebase?
- Firebase query sort order in swift?
Firebase Sorting is not working properly in flutter
It looks like the values in your episodeNum
field are stored as string values, and not as numbers. And in the lexicographical ordering (which Firestore uses for string values) "10" comes before "2", just as "aa" comes before "b".
To fix the problem, store the episodeNum
values as numbers in the database, and Firestore will order them correctly.
Firebase orderByChild Order Is Not Correct
Your scores are strings. They should be numbers instead. Strings don't sort like numbers.
Firestore query orderBy not working?
I think you are missing a '
here '_timeStampUTC
, so it should be:
orderBy('_timeStampUTC', descending: true)
EDIT:
Also, you need to be sure to create an index for toid
and other for _timeStampUTC
, this is done when you try to order by a property that is not in you the where of the query.
Related Topics
Previewprovider and Observedobject Properties
Xcode 7.3.1 Hangs on "Copying Swift Standard Libraries"
Try, Try! & Try? What's the Difference, and When to Use Each
How to Silence a Warning in Swift
Swift Cross Compile to Single Linux Binary
Change the Value That Is Being Set in Variable's Willset Block
How to Convert Hex Number to Bin in Swift
Swift - How to Mutate a Struct Object When Iterating Over It
How to Access Program Arguments in Swift
Get Button Pressed Id on Swift Via Sender
Programmatically Screenshot | Swift 3, Macos
Get the Top Viewcontroller in iOS Swift
Firebase Snapshot.Key Not Returning Actual Key
Whats the Swift Animate Withduration Syntax
Swift - Increment Label With Stepper in Tableview Cell
No Such Module 'Restkit' With Cocoapods and Swift
Swiftui: Can't Get the Transition of a Detailview to a Zstack in the Mainview to Work