Issue
How can I update a field to a document, while getting the the fields of that document? I am unsure how to do so given my setup. It appears that I can't use .update() with my code as I get an unresolved reference: update error.
class ReminderActivity : AppCompatActivity() {
lateinit var reminderID: String
val db = Firebase.firestore
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_reminder)
val completeTask: Button = findViewById(R.id.complete_button)
completeTask.setOnClickListener {
db.collection("pets").document("vNkkDGAS1oBMpanEXhte").collection("reminders").document(iFdIMKSxJV79Mm64OHwp).get().addOnSuccessListener { document ->
val timeStamp = document.get("timestamp") as com.google.firebase.Timestamp
val millisec = timestamp.seconds * 1000 +timestamp.nanoseconds/1000000
val netDate = Date(millisec)
val frequency = document.get("frequency").toString()
val cal: Calendar = Calendar.getInstance()
cal.time = netDate
val time = Timestamp(cal.timeInMillis)
document.update({timestamp: time}) //<- line not working
}
}
}
}
pictures of cloud firestore database

Solution
I believe document is of type DocumentSnapshot class and you can't update with this object. Update can only be done from DocumentReference class object. You need to update the implementation for updating the document.
Answered By - Malik Basit


0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.