【问题标题】:Why is my code writing the full path of the doc ID in Firestore?为什么我的代码要在 Firestore 中编写文档 ID 的完整路径?
【发布时间】:2020-12-22 03:34:50
【问题描述】:

如何单独编写文档 ID 而不是完整路径?目前我的代码正在插入users/pdqr4LyHzbuGle0e8sCr。我宁愿它插入pdqr4LyHzbuGle0e8sCr

var collUsersRef: CollectionReference = db.collection("users")
val doc = collUsersRef.document()
var data: HashMap<String, Any> = hashMapOf(
                        "docID" to doc
                        , "email" to email
                        , "username" to user
                        , "createDate" to FieldValue.serverTimestamp()
                        , "modifiedDate" to FieldValue.serverTimestamp()
                        , "stat" to 1
                    )

 doc.set(data)

【问题讨论】:

  • 建议你澄清这个问题。该代码没有明确提及任何“文档 ID”。

标签: android firebase kotlin google-cloud-firestore


【解决方案1】:

使用DocumentReference对象docid属性(java getter getId()):

"docID" to doc.id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多