I’m trying to make a database to save check-in and check-out times, But when using my code, the hours are overwritten instead of being saved one after the other. I have no idea how to do it
This is part of the code I’m using, but the problem is that the "input" field gets overwritten all the time.
My question is, does anyone know a way to save the data one by one, without overwriting it? Because the code works but I want to see all the input and output records. and I didn’t find a way to do it.
I am using Kotlin as a programming language and Android Studio.
val dateStringEntrada = "${now.year}-${now.monthValue}-${now.dayOfMonth}" +
" ${now.hour}:${now.minute}:${now.second}"
db.collection("entradas").document(mail.toString()).update(
"entrada", dateStringEntrada
)
2
Answers
I'm trying to find a solution but it keeps overwriting the data. my code looks like this:
val dateArray=dateStringEntrada.split("")
dateStringEntrada.forEach{ dateArray.add(it.toString()}
db.collection("entradas").document(mail.toString()).set( mapOf("entrada" to dateArray) )
When you’re calling
update()
on the DocumentReference object, theentrada
field will be updated (overwritten) each time you callupdate()
. If you want to have multipledateStringEntrada
then you have to store them in a field that allows that. So to solve this, you should store them in an array rather than in a string. If you however need multipledateStringEntrada
in different documents, then you can have the sameentrada
field with different values in multiple documents.