Eri*_*rik 5 database android firebase firebase-security google-cloud-firestore
我刚刚开始迁移到 Cloud Firestore,并对这条安全规则感到好奇。\n在 Firebase 实时数据库中,这条规则:
\n\n\n\n\n如果规则表达式中的一个操作数为 true,则计算结果为 true。
\n\n在这个例子中,只要旧数据或新数据不存在,我们就可以写入。换句话说,如果我们要删除或创建数据,但不更新数据,则可以写入。
\n\n".write": "!data.exists() || !newData.exists()"
\n
I\xc2\xb4m 尝试在 Cloud Firestore 中复制,例如
\n\n\n\n\nRun Code Online (Sandbox Code Playgroud)\nmatch /USER_ID/{Id} {\n allow create: if resource.data.id != exist\n allow read: if request.auth.uid != null;\n }\n
我想要的是,如果Document存在,则USER_ID Collection发生的事务必须失败。\n但这不起作用。我已阅读该文档几次但无法使其工作
您将需要使用存在函数,为此您需要将正在测试的文档的路径传递给它(如果存在)。下面是如何检查文档是否不存在的示例。
service cloud.firestore {
match /databases/{database}/documents/ {
match /USER_ID/{Id} {
allow create: if !exists(/databases/$(database)/documents/USER_ID/$(Id))
allow read: if request.auth.uid != null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1089 次 |
| 最近记录: |