Reputation: 3195
I have the below data structure in Firebase database and I would like to order keys of the 2017 branch as shown below in the screenshot. However when I get the keys the first items returned are 10, 11, 12 before 01, 02, 03, 04, 05, 06, 07, 08 ,09. The order should be as the screen shot.
My database call is
databaseRoot.ref('contractors/' + userObject.uid + '/timesheets').once('value', function(snapshot) { });
I also tried orderByKey() but I get the same results
Upvotes: 1
Views: 520
Reputation: 7668
You were right to remove the prefixed 0. It's because Firebase Database keys are strings ordered lexicographically, and therefore it was returning them in an 'unnatural' looking order.
Upvotes: 1