我正在将firestore用作事件应用程序的API端点,并且需要能够为集合写入数据。如何编写规则?
该应用程序没有身份验证(它是完全公开的),因此我尝试了以下规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if true;
}
}
// Need to be able to write documents into the silent_disco collection
match /databases/silent_disco/documents {
match /{document=**} {
allow write: if true;
}
}
// Need to be able to write into the passport collection
match /databases/passport/documents {
match /{document=**} {
allow write: if true;
}
}
}
使用模拟程序时,我可以按预期读取所有内容,但是写入请求被拒绝。
答案 0 :(得分:1)
以下方法应该起作用:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if true;
}
// Need to be able to write documents into the silent_disco collection
match /silent_disco/{docId} {
allow write: if true;
}
// Need to be able to write documents into the passport collection
match /passport/{docId} {
allow write: if true;
}
}
}
您可以观看有关以下主题的出色的官方视频:https://www.youtube.com/watch?v=eW5MdE3ZcAw