gpt4 book ai didi

firebase - Firestore 安全规则 : check for not exists(/collection/document)

转载 作者:行者123 更新时间:2023-12-03 22:25:54 25 4
gpt4 key购买 nike

在 firebase firestore 安全规则中,我只想在特定文档不存在时才允许请求。我的代码是:

match /users/{user_id} {
allow create: if !exists(/databases/$(database)/merchants/$(request.auth.uid));
}

我很确定该文件不存在,但它不起作用。
两者 exists()!exists()以某种方式给出错误,或者可能 !exists()引发一些错误。
我什至尝试过:
match /users/{user_id} {
allow create: if exists(/databases/$(database)/merchants/$(request.auth.uid)) == false;
}

有什么办法可以使这项工作?

最佳答案

您的规则是否在数据库块内?因为我遇到了类似的问题,实际上是将规则放在数据库块下方,而我的规则使用的是 $(database)参数和你一样

service cloud.firestore {
match /databases/{database}/documents {
match /users/{user_id} {
allow create: if !exists(/databases/$(database)/merchants/$(request.auth.uid));
}
}
}

关于firebase - Firestore 安全规则 : check for not exists(/collection/document),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47951081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com