Home > OS >  Write to Firebase with serial number indexing
Write to Firebase with serial number indexing

Time:10-11

enter image description here

The data in LiveAutos is set using:

ref.child("hhh@hgh").child("latitude").setValue(location.latitude)

the data in Livelyautos is set using a python script by uploading a JSON file.

How can I write the data in LiveAutos similar to the LivelyAutos with serial numbers 0,1,2,3. the database will be updated by multiple devices locations.

or how can I read the data from LiveAutos?

CodePudding user response:

As @FrankvanPuffelen mentioned in his comment, storing sequential numeric elements is not a recommended way of adding data to Firebase Realtime Database, is rather an anti-pattern, since such a schema doesn't scale. What you can do is to use the push() method:

ref.child("hhh@hgh").push().child("latitude").setValue(location.latitude)

Which will produce a schema that looks like this:

Firebase-root
 |
 --- hhh@hgh
      |
      --- $pushedId
             |
             --- latitude: 0.00
             |
             --- longitude: 0.00

In this way you can add as many locations as you want.

  • Related