简体   繁体   中英

how to add id of document in filds firestore

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.

whats i want in photo在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM