# Realtime DB Order of Entry

**URL:** <https://community.thunkable.com/t/realtime-db-order-of-entry/1926371>\
**Category:** Questions about Thunkable X\
**Tags:** design, realtimedb\
**Created:** [June 15, 2022, 12:10pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371 "2022-06-15T12:10:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [June 15, 2022, 12:10pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/1 "2022-06-15T12:10:30Z")

</div>

Hello Thunkers,  
I have question , when we create new entry in realtime db it has been observed that , the order of entry is not sequential.

Is this expected behavior, or there is some bug in my code.  
Can we do anything to keep dates in sequential manner ??

I am using cloud variable to add entry into realtime DB.

I am preparing graphs which would be taking data from realtime db, hence i want them sequential.

Please help, Thanks Rohan

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/8/78b4fc377a3feaffe3104cd95f12e874130d8900.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 15, 2022, 1:54pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/2 "2022-06-15T13:54:16Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 15, 2022, 1:54pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/3 "2022-06-15T13:54:44Z")

</div>

Yes, this is an expected behavior. RTDB will store the data in an object but might not keep the order it was created with.

> [@r0han](#):
>
> hence i want them sequential.

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.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [June 15, 2022, 2:05pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/4 "2022-06-15T14:05:08Z")

</div>

Is it returning th in alphabetic order?

> [@muneer](#):
>
> `s` to force the order but RT

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.

 ![Screen Shot 2022-06-15 at 10.08.49 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/a/6a96e10c7edb02473ecc11400f8a747754754091.png)  
^^^ read data from FB

 ![Screen Shot 2022-06-15 at 10.06.32 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/0/204728f18e250b4294ab030501040add96d47bd2.png)  
^^^ data model for each object saved under a key of “`seconds since 1970`”

 ![Screen Shot 2022-06-15 at 10.05.51 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/e/6e5efc250304bac37e6bae361c5f1e1a0348baaf.png)  
^^^parsing the list from firebase. (i never noticed they were out of order 😂 )

 ![Screen Shot 2022-06-15 at 10.06.38 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/0/0049fd2d18ef816bf7fbc84ac0e554abb80458c6.png)  
^^^saving a score

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 15, 2022, 2:13pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/5 "2022-06-15T14:13:42Z")

</div>

> [@jared](#):
>
> returning th in alphabetic order?

The alphabet order will sort the entries as follows:

- 1^6^2022
- 14^6^2022
- 9^6^2022

Which is the wrong order of dates.

---

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [June 15, 2022, 5:07pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/6 "2022-06-15T17:07:31Z")

</div>

Thanks Tatiang, i am inserting as an when they are created. The problem is they are inserted in alphabetic order, i think.

---

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [June 15, 2022, 5:16pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/7 "2022-06-15T17:16:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 15, 2022, 6:29pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/8 "2022-06-15T18:29:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![r0han](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/r0han/32/130614_2.png) [@r0han](https://community.thunkable.com/u/r0han)\
**Post date:** [June 15, 2022, 6:52pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/9 "2022-06-15T18:52:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 15, 2022, 7:06pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/10 "2022-06-15T19:06:23Z")

</div>

> [@r0han](#):
>
> I am not using a list, user updates their profile every week.

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [September 13, 2022, 7:07pm UTC](https://community.thunkable.com/t/realtime-db-order-of-entry/1926371/11 "2022-09-13T19:07:07Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
