skip to Main Content

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
)

firebase and code in kotlin

2

Answers


  1. Chosen as BEST ANSWER

    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) )


  2. When you’re calling update() on the DocumentReference object, the entrada field will be updated (overwritten) each time you call update(). If you want to have multiple dateStringEntrada 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 multiple dateStringEntrada in different documents, then you can have the same entrada field with different values in multiple documents.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search