2

I am looking into how Firebase RealTime Database stores values. For example: if the data type is number and instead of a number I store null, does it allocate 1 byte or 8 byte? I can't find anything about it in the documentation.

Second concern is: I am sending a geolocation point. In the database I want to check if it is cast to float or geopoints data type. How can I check?

Fahad Abid
  • 1,012
  • 9
  • 20
  • Firebase does not support *storing* a 'Null', and if you set a nodes value to Null (nil) it will be removed. See my answer to [this question](https://stackoverflow.com/questions/38462074/using-updatechildvalues-to-delete-from-firebase/38466959#38466959) on how to remove multiple nodes at one time using NSNull (ObjC) – Jay Jan 17 '18 at 21:01

1 Answers1

6

The Firebase Realtime Database is just a JSON tree. You can imagine it as being a large Text file that contains a very large String (and that string is your database). Text files don't really parse through data types, which means that if you store null, it sums up 4 bytes (1 byte per character) and storing the number 4 for example will be allocating 1 byte.

Answering the second question: The only data types supported by the Firebase Realtime Database (Android) are:

  1. String
  2. Long
  3. Double
  4. Boolean
  5. Maps
  6. Lists

That means that your Geolocation will be cast to Double.

Edit: ObjC/Swift data supported data types are

NSString
NSNumber
NSDictionary
NSArray
Jay
  • 34,438
  • 18
  • 52
  • 81
  • [Firebase Cloud Firestore](https://firebase.google.com/docs/firestore/) on the other hand has a wider variety of [data types](https://firebase.google.com/docs/firestore/manage-data/data-types) including Geographical points. You might want to have a look at it. – Rosário Pereira Fernandes Jan 16 '18 at 23:11
  • 3
    Good answer! As a side note, Firebase does not support storing a 'Null' data type. i.e. every key must have a value of one of the above mentioned ones - a value cannot be nil/null and if it is, the node will be removed. – Jay Jan 17 '18 at 20:58