简体   繁体   English

在 Firestore 中创建 UID 作为字段

[英]Creating a UID as a field in Firestore

I want to be able to create a UID as a field inside my collection in firestore, is that possible?我希望能够在 firestore 的集合中创建一个 UID 作为字段,这可能吗?

Ex: The UID would be a generated field that creates a "project" and that project will have it's own UID, so that it stays unique.例如:UID 将是创建“项目”的生成字段,并且该项目将拥有自己的 UID,因此它保持唯一。 How can I accomplish this?我怎样才能做到这一点?

在此处输入图像描述

Yes, it is very possible是的,很有可能

val id uuid = UUID.random()
    val city = hashMapOf(
            "UID" to uuid
            "name" to "Los Angeles",
            "state" to "CA",
            "country" to "USA"
    )
    
    db.collection("cities").document(uuid)
            .set(city)
            .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully written!") }
            .addOnFailureListener { e -> Log.w(TAG, "Error writing document", e) }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase firestore 未使用最近创建的 uid 创建文档 - Firebase firestore not creating doc with recently created uid 如何在 Firebase Firestore 中添加自动 uid 字段 - How to add auto uid field in Firebase Firestore 将 UID 与文档字段匹配的 Firestore 规则不起作用 - Firestore Rules matching UID with Document Field not working Firestore:使用指定的UID创建文档,最终使用set()创建文档,但不更新字段 - Firestore: Creating a document with specified UID, eventually with set(), but without updating the fields 如何通过查看 UID 在 Firestore 数据库中设置新字段 - How to set a new field in a firestore database by looking at the UID 如何使用 uid 文档 ID FirebaseAuth Firestore 获取 Firestore 字段信息 - How to get Firestore field information using an uid document id FirebaseAuth Firestore 获取Firestore的UID参考 - Getting UID Reference for Firestore 使用文本字段数据创建 Firestore 文档 - Creating Firestore document with text field data 如何匹配存储在 Firestore 的 Firebase 安全规则内的文档字段中的用户 uid - How to match a user's uid stored in document field inside Firebase security rule for Firestore Firebase Firestore 安全规则 | 如果字段值与 auth uid 相同,则允许读取 - Firebase Firestore Securitty Rule | Allow read if field value same as auth uid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM