I am developing a inventory application in which a unique auton-increment value needs to be generated for creating product ids.
Little confused how to generate a custom auto-increment id using firebase as back-end service.
I am developing a inventory application in which a unique auton-increment value needs to be generated for creating product ids.
Little confused how to generate a custom auto-increment id using firebase as back-end service.
The Firebase Database equivalent of an auto-increment columns is called a push ID. These keys are generated when you call push()
(or on iOS childByAutoId
) and they are:
But unlike the auto-increment columns in SQL databases:
Instead of 1
, 2
, 3
, you'll get value like "-KqB_B7Rh8cTYQxihbpb"
, "-KqB_CfSXYZ3kp0a_WlT"
, "-KqB_CuTwYXn-UtUEv0s"
. While they may be a bit harder to get used to, the advantages are well worth it.
I recommend reading more in these two blog posts:
Every time you insert data in Firebase, a unique id (UUID) is generated for object. The recommended practice is to use that firebase-generated UUIDs or a custom UUID, but not an auto-increment id (Check this question)