![](/img/trans.png)
[英]How to add Document with Custom ID to firestore in firestore 9
[英]how to add id of document in filds firestore
我有 firestore 数据库,其中有一个字段在创建文档后调用 idDoc 我想在 idDoc 中添加文档 ID 我这样做 function
fun updateNotesDocId(userId: String){
notesChannnelsCollectionRef.document(userId)
.collection("notes")
.document(notesChannnelsCollectionRef.document().id)
.update(mapOf(notesChannnelsCollectionRef.document().id to "idDoc"))
并且此代码不起作用。 我交换了一切。
每次调用不带参数的document()
都会为您提供具有不同随机 ID 的 DocumentReference。 您将只想调用它一次,记住结果并重用它。
val ref = notesChannnelsCollectionRef.document()
notesChannnelsCollectionRef.document(userId)
.collection("notes")
.document(ref.id)
.set(mapOf("idDoc" to ref.id))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.