简体   繁体   English

Firebase 以数字开头的集合规则不起作用

[英]Firebase rule for collection start with number doesn't work

I have a collection called 2022collection but when I go to set the read access in Firestore rules it errors out, I've searched the docs and stackoverflow and am not seeing anything anywhere on how to write the rule properly to allow a collection starting with a number.我有一个名为 2022collection 的集合,但是当我 go 设置 Firestore 中的读取访问规则时它出错了,我搜索了文档和 stackoverflow,但没有看到任何关于如何正确编写规则以允许以数字。 I can write and read to it just fine if I'm logged in to the app, but unable to make a firestore rule to make it publicly readable.如果我登录到应用程序,我可以很好地写入和读取它,但无法制定 firestore 规则以使其公开可读。 Rules for collections that start with a letter work just fine but the number errors out completely.以字母开头的 collections 规则工作正常,但数字完全错误。

How do I make a Cloud Firestore rule for a document/collection that starts with a number?如何为以数字开头的文档/集合制定 Cloud Firestore 规则?

Here are a couple things I've tried, clearly neither work.这是我尝试过的几件事,显然都没有用。 I would argue that there should be better documentation on this as I've failed to find anything that explains it.我认为应该有更好的文档,因为我找不到任何解释它的东西。 Happy to be proved wrong if such docs exist, I've not found them in an all my time searching here .如果存在这样的文档,很高兴被证明是错误的,我一直在这里搜索都没有找到它们。

在此处输入图像描述

在此处输入图像描述

You can use a wildcard to read collection name and then use matches() to check if it starts with a number.您可以使用通配符读取集合名称,然后使用matches()检查它是否以数字开头。 Try the follwoing rules:尝试以下规则:

match /{col}/{docId} {
  allow read, write: if col.matches("^[0-9].*");
}   

Do note that this rule will be applied for all collections since you have a wildcard.请注意,此规则将应用于所有 collections,因为您有通配符。

I ended up fixing it by changing my code from我最终通过更改我的代码来修复它

match /2022users/{2022users} {
    allow read;
    }

to

match /2022users/{users2022} {
    allow read;
    }

After changing the second field I was able to save the rule and read the collection 2022users.更改第二个字段后,我能够保存规则并读取集合 2022users。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM