beratuslu
beratuslu

Reputation: 1119

Pyrebase updating fields vanishes the other fields

I am using Pyrabase(python wrapper for the Firebase API). I am trying to update a child's only one field like following, when I run the below code it vanishes, "anotherField"s do you guys any idea how to to it without touching "anotherField"s?

My firebase db is like:

{
   "weather":{
      "Los Angeles":{
         "anotherField":"something",
         "isSunny":false
      },
      "istanbul":{
         "anotherField":"something",
         "isSunny":false
      }
   }
}

I am trying to do update with the following data:

dict = {
   "Los Angeles":{
      "isSunny":true
   },
   "istanbul":{
      "isSunny":true
   }
}

db.child("weather").update(dict)

Upvotes: 1

Views: 585

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599131

Calling update on the Firebase Database works only one level down. It essentially loops over the first level of your dictionary, and performs a set on each key under that.

If you want to selectively replace lower level properties, you will need to put the path to each property into the top level of the dictionary:

dict = {
   "Los Angeles/isSunnry": true,
   "istanbul/isSunny": true
}

db.child("weather").update(dict)

Upvotes: 1

Related Questions