[英]Allow user to update his own document (but not the roles) using Firestore security rules
[英]How to update a document in Firestore just using his unique id?
有什么方法可以在集合中的 Firestore 中更新具有唯一 ID 的文档,但不指定父集合?
正如您在下面的代码中看到的,我可以指定“用户”集合、uid 和 id。 但是我没有办法在集合中指定我要更新的元素的父集合。
await updateDoc(doc(collection(db, 'users', uid, unspecifiedCollection), id), {
content
})
有没有人有解决这个问题的想法?
要更新文档,您必须指定该文档的完整路径。 如果不指定文档的完整路径,则无法更新文档。
通常,在 Firestore 中建模数据时的最佳做法是使用固定/已知的集合名称和动态/生成的文档 ID。
如果您不知道集合的名称,这通常意味着您应该更改数据 model 以便始终知道它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.