compli
compli

Reputation: 61

I cannot create new child in realtime database through loops

def create(grpname,name,price,movement,percentage):
   
    firebase = pyrebase.initialize_app(firebaseConfig)
    database = firebase.database()
    data = {
            grpname:{
                "name":name,
                "price":price,
                "movement":movement,
                "percentage":percentage
            

        }
    }
    database.set(data)

This is my code, im running a for loop for this (50 iterations). But the thing is in the database instead of creating 50 different childs its overwriting the one created before it. Any help to correct this?

Upvotes: 0

Views: 74

Answers (1)

DIGI Byte
DIGI Byte

Reputation: 4164

This would be due to the fact you are referencing the Root of your database with firebase.database() but when it comes to setting your data, you aren't assigning it by any unique child node.

If you want a new child you should consider using an add() method instead of set() just be aware that if you want the node to be the value of grpname you should set the child node in the database reference with .child(grpname).set() instead

Upvotes: 1

Related Questions