Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Firebase keys unique to the whole database?

When using push() Firebase creates a unique ID or key such as -KKm9iRSax-scGn7m3Lb.

According to the docs:

The push() method generates a unique ID every time a new child is added to the specified Firebase reference.

And:

The unique ID generated by push() is based on a timestamp, so list items are automatically ordered chronologically.

Is this ID or key unique to the whole database or only to the reference (like /users)?

like image 339
Pier Avatar asked Jul 05 '16 15:07

Pier


People also ask

Is Firebase a key-value database?

Firebase uses a very popular style of NoSQL database: Key-value stores. The concept is not so complicated once you know the basic JSON syntax.

Is Firebase ID unique?

Is Firebase id unique? Firebase users have a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web).

Is Firebase a key-value store?

Firebase is categorized as a NoSQL database program, which stores data in JSON-like documents. In Firebase, a document is a set of key-value pairs defined by a schema.

How can we create a unique key and use it to send data in Firebase?

You can create a unique key in Firebase database using push() and then add child nodes under that key. Now next time when you come to that activity, first check if parent node exists or not. If the node exists, save parent node key and use it to save new child nodes.


1 Answers

Firebase keys are part timestamp and part random characters. So while they should be unique across the whole database there is a small chance that two keys could end up being the same.

Firebase blog: The 2^120 Ways to Ensure Unique Identifiers

like image 162
alecschrader Avatar answered Nov 05 '22 06:11

alecschrader