google-cloud-firestore - firebase 规则应该如何在收集数据中找到并检查是否存在?
问题描述
创建新文档时(在我的示例中,这是配置文件文档),安全规则应检查包含此电子邮件的配置文件是否已存在。我创建了一个附加功能,它应该在“个人资料”集合中搜索所有带有特定电子邮件的个人资料,并返回是否已经收到电子邮件。
该文档提供了示例(链接):
service cloud.firestore {
match /databases/{database}/documents/some_collection: {
// Remember that, in Cloud Firestore, reads embedded in your rules are billed operations
write: if request.auth != null && get(/databases/(database)/documents/users/$(request.auth.uid)).data.admin) == true;
read: if request.auth != null;
}
}
但我不能使用它,因为我没有特定的个人资料 ID,我需要通过电子邮件查找此集合中的所有个人资料。
我的代码:
match /profiles/{profileId} {
allow create: if allowToCreateProfileWithEmail(request.resource.data.email);
function allowToCreateProfileWithEmail (email) {
let profiles = firebase.firestore().collection("profiles").where("email", "==", email).get();
return profiles != null;
}
但这是行不通的,因为firebase
不存在。我怎样才能修复我的代码来解决我的问题?
解决方案
推荐阅读
- python - python函数在许多文件上打印到stdOut
- python - 创建一个包含多个数据类实例的 Python 列表
- android - MoPub 在使用测试广告单元 ID 时未找到任何广告
- python - overrideredirect 如何影响 winfo_height/width?
- oracle - Oracle 过程从表中选择数据,从 all_tab_columns 传递列
- c++ - 重载 >> 运算符时的非法指令
- python - 递归地打乱列表
- php - PHP通过带有stdObjects的多维数组进行多次循环
- python - 具有复杂标准的python pandas重复数据删除
- c++ - 无法累积编译时间常数