Reputation: 39
i have firestore database where is a field which call idDoc after create a document i want to add a document id in idDoc i do this function
fun updateNotesDocId(userId: String){
notesChannnelsCollectionRef.document(userId)
.collection("notes")
.document(notesChannnelsCollectionRef.document().id)
.update(mapOf(notesChannnelsCollectionRef.document().id to "idDoc"))
and this code doesnt work. I swapped everything.
Upvotes: 0
Views: 47
Reputation: 317487
Each call to document()
with no parameters will give you a DocumentReference with a different random ID. You will want to just call it once, remember the result, and reuse it.
val ref = notesChannnelsCollectionRef.document()
notesChannnelsCollectionRef.document(userId)
.collection("notes")
.document(ref.id)
.set(mapOf("idDoc" to ref.id))
Upvotes: 1