'Firebase Firestore: Update a field of a document in a subcollection while retrieving information
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
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|



