Alex McPherson
Alex McPherson

Reputation: 3195

Firebase database ordering by keys number

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) { });

enter image description here

I also tried orderByKey() but I get the same results

Upvotes: 1

Views: 520

Answers (1)

Bradley Mackey
Bradley Mackey

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

Related Questions