Firebase 如何在filds firestore中添加文档id
我有firestore数据库,其中有一个字段,在创建文档后调用idDoc。我想在idDoc中添加文档id。我执行此功能Firebase 如何在filds firestore中添加文档id,firebase,kotlin,google-cloud-firestore,Firebase,Kotlin,Google Cloud Firestore,我有firestore数据库,其中有一个字段,在创建文档后调用idDoc。我想在idDoc中添加文档id。我执行此功能 fun updateNotesDocId(userId: String){ notesChannnelsCollectionRef.document(userId) .collection("notes") .document(notesChannnelsCollectionRef.document().i
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))
哦,也许我会证明我自己很愚蠢,我将你的代码集成到我的代码中,但这不起作用,可能是因为一个
private val noteschannnelscolectionref=firestoreInstance.collection(“notesChannels”)
我对apdate有问题,``未找到:没有要更新的文档:项目/毕业作品/数据库/(默认)/documents/noteshannels/kWvT6j7ObVfjVDy2iE2nITwep0V2/notes/noteshannels```set()删除所有字段并设置一个“idDoc”是否生成新文档?请编辑问题以明确您希望发生的事情。如果只是更新现有文档,则需要知道其ID。如果不知道文档存在,则不能调用update()。