The “6” property has sub-properties for each date. Those will be alphabetized (sorted) by Firebase. Instead, you need to use a list. So you would insert a value as the last item in the list at “6”.
Yes, this is an expected behavior. RTDB will store the data in an object but might not keep the order it was created with.
You can use the IndexOn property in the Rules to force the order but RTDB only understands dates as unix timestamp so you need to add this field and sort using it.
You could use the time since 1970 as the key value
you’d get the keys of the value 6 (6 would be an object that’s returned from firebase)
sort that list ascending
loop over that list and pull the properties from each corresponding key/value pair from the object 6
^^^this is how i deal with time based lists in firebase/thunkable. for example in the following images i would be saving a list of study scores under a user id as a list.
I am storing Current and Target weight against these dates and preparing graph for the same. I can sort dates but then i have to make sure associated current weight and target weight does not sort. Looks tricky…
They shouldn’t be sorted at all if you are using a list. Unless I’m mistaken but I don’t think Firebase would ever auto-sort a list. Are you sure you are inserting the new values as the last item in the list?
I am not using a list, user updates their profile every week. I am making an entry to RTDM based on date it was entered. Entry was done on 1st and 9th , when 14th entry came , RTDM inserted in between of these days based on its sorting Logic.
What i did to fix is i removed ^ when entry is made, so that the date of entry is ordered. And Then i added Date field inside this Object. Ex.
162022
|_Weight
|_Target
|_Date
Since Date is sorted, For loop will run thru these days and insert Date, Weight and Target in the list. And it would be displayed in graph.
Right but you could just as easily update a list when the user updates their profile. Perhaps you don’t want to do that but that’s how I’ve set up a photo journal app using Firebase so that entries are chronological.