![](/img/trans.png)
[英]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.