简体   繁体   中英

how do you retrieve a auto generated id to delete data in firebase

Im trying to delete this data in the app but im not sure how to retrieve the uid of the one i need to delete:

so the first id is the current users id but how do i get the next unique id fo i can delete the records "test" and "Apple"

this is how i upload the data to the database:

var currentUid = mAuth.currentUser?.uid
val myRef = database.getReference("Users")
val myRefCategory = myRef.child(currentUid!!).child("Following")


  fun sendDataToDatabase(category: String) {

    myRefCategory.push().setValue(category)

  }

how do i get the "MLt1lk1wtyvqLtQGZRF" and "MLt1bpUmJmAkjz_7tGN"?

在此处输入图像描述

The key you're looking for is in the DatabaseReference returned by push() .

val ref = myRefCategory.push()
val key = ref.key  // this is your key
ref.setValue(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM