How to sort Firebase Keys in ascending order?

无人久伴 提交于 2019-12-05 22:41:53

Firebase keys are strings. And when you order string data, it is ordered lexicographically.

So for numbers, this is the normal order:

  • 1
  • 9
  • 10
  • 11

But for strings, this is the normal order:

  • "1"
  • "11"
  • "19"
  • "9"

There is no operator in Firebase (nor in most other databases) to change this behavior. Instead, you will have to modify the data to get the behavior you want. So: store values that are in the order you need them when sorted lexicographically. For numbers you can accomplish that by padding them with zeroes:

  • "001"
  • "009"
  • "011"
  • "019"

Or in your case c09p010, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!