Gino Sesia
Gino Sesia

Reputation: 393

How to add data to firebase realtime database on android using Kotlin?

When I upload data to the fire base realtime database it uploads everything perfectly but when I register a new user the previous users data gets deleted every time a new user is created

this is the code I use to upload the data:

private fun uploadUserDataToDatabase(email: String) {

    var uid = mAuth.currentUser?.uid
    var user = User(email)

    myRef.child(uid!!).setValue(user)

}

This is what the data base looks like after a user has registered:

enter image description here

This is what the database looks like after a nother user registers:

enter image description here

How do i get it to not delete the previous user everytime a new user is registered?

if i change it to

myRef.child(uid!!).push.setValue(user)

it uploads the data twice and looks like this:

enter image description here

Upvotes: 0

Views: 1293

Answers (1)

Wahdat Jan
Wahdat Jan

Reputation: 4156

myRef.child(uid!!).push().setValue(user)

Upvotes: 1

Related Questions