[英]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.