如何使用Kotlin从Firestore Firebase获取数据路径

时间:2020-05-13 15:13:04

标签: firebase kotlin google-cloud-firestore

我创建了一个记事应用程序,在该应用程序中,我使用此命令将一些信息发送到Firestore 发送方法

val notesToSend = NotesModel(
                noteTitle,
                noteText,
                Calendar.getInstance().time,
                FirebaseAuth.getInstance().currentUser!!.uid,
                FirebaseAuth.getInstance().currentUser!!.uid,
                currentUser.name
            )

            FirestoreUtil.sendNotes(notesToSend, FirebaseAuth.getInstance().currentUser!!.uid)

发送注释

private val notesChannnelsCollectionRef = firestoreInstance.collection("notesChannels")

    fun sendNotes(notes: Notes,userId: String){
        notesChannnelsCollectionRef.document(userId)
            .collection("notes")
            .add(notes)
    }

如何从数据库获取数据路径?

数据库图片 enter image description here enter image description here

1 个答案:

答案 0 :(得分:2)

正如Puff在here上所指出的那样,它提到了如何使用文档参考来获取文档。 here是Firebase SDK,在其中分析DocumentReference类,您可以使用函数getPath()从Reference获取路径

因此获取路径的代码将是:

val docRef = db.collection(COLLECTION_ID).document(DOCUMENT_ID)
val docPath = docRef.getPath()