1

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

3
  • I am not an expert in firebase-realtime-database, but in cloud-firestore there is a function .add() which does not override the old value. So I would try .addValue() instead of .setValue() Commented Nov 9, 2020 at 14:41
  • That last screenshot looks as expect when you call push(). If tht is not what you want, edit your question to show the JSON you want to get. Commented Nov 9, 2020 at 15:19
  • In the first two screenshots, there are two different UIDs, I cannot see any reason why one of them is deleted unless you are especially doing it in your code. Commented Nov 9, 2020 at 18:17

1 Answer 1

1
myRef.child(uid!!).push().setValue(user)
Sign up to request clarification or add additional context in comments.

11 Comments

if i change it to that it uploads the data twice. i've added it to the question so you can see
no because as soon as i register another user id deletes the previous users data
u added to ur question thats not deleting
i dont understand
what u want then?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.