1

the Below code replaces the previous entry but i want to add new entry or append the new entry in the child name Friends_email please if any one can help me. I am using python 3.9 with Pyrebase 3.0.27.

li = {"1":"gurjar"}
db.child("Users").child("nishant").child("Friend_list").child("Friends_email").set(li)
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

2 Answers2

1

Calling set overwrites the existing data at the path with the new data you specified. If you want to add a new child under the path with the new data, use push. If you want to merge the new data with the existing data at the path, use update.

Also see the Pyrebase documentation on push and update.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks for your answer but push creates a new child it does not append the value in another child and update changes the whole value I just want to append new data in previous child only don’t want to create a new child. – Harsh Gurjar Apr 15 '21 at 15:18
  • I think at this point it is safe to say that I don't understand what you want. Please edit your question to show the JSON you have under `Friends_email` and what you want it to be be after the code runs. – Frank van Puffelen Apr 15 '21 at 15:26
  • Thanks for your time but i solved it myself – Harsh Gurjar Apr 15 '21 at 16:03
  • Good to hear. Can you post your solution as an answer, so others can benefit from it too? – Frank van Puffelen Apr 15 '21 at 17:05
1

Yes previously I was writing.

li = {"1":"gurjar"}
db.child("Users").child("nishant").child("Friend_list").child("Friends_email").set(li)

But now I am using

db.child("Users").child("nishant").child("Friend_list").child("Friends_email").child(1).set(“gurjar”)

Now if I will change child 1 to 2 then it will append it in the child Friends_email.