如何在不使用get()的情况下,根据父集合中的字段来控制Firestore子收集?

发布于 2025-01-28 08:24:13 字数 388 浏览 2 评论 0原文

我在下面有此代码,但是在我的代码中导致额外的读取,我得到了数据集合中存储的值(premiumuntill)收藏。在检查父母集合中某些先前值的状态时,是否还有其他方法不会引起额外的读取,或者这是唯一的方法。

match /Data/{dataDocId}/SubData/{subdataDocId} {
    allow get: if request.auth != null 
    allow create: if request.auth != null  
    && get(/databases/$(database)/documents/Data/$(dataDocId)).data.premiumUntill > req.time
}

I have this code below that is working, but it causes extra reads in my code, I am getting the value that is stored inside the data collection (premiumUntill) in order to allow/block Crud in to sub collection. Are there any other methods that won't cause extra reads when checking for the state of some previous value located in a parent collection or is this the only way.

match /Data/{dataDocId}/SubData/{subdataDocId} {
    allow get: if request.auth != null 
    allow create: if request.auth != null  
    && get(/databases/$(database)/documents/Data/$(dataDocId)).data.premiumUntill > req.time
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只有影子陪我不离不弃 2025-02-04 08:24:13

如果您使用get()从其他文档中读取数据,那么您将被读取。防止从Firestore规则中读取的另一种方法是将Premiumuntill存储在自定义索赔。您需要一个云功能来设置自定义索赔,但最好的是,您可以从任何其他壁炉服务(例如存储和实时DB)访问Premiumuntill。

If you are reading data from other documents using get() then you'll be charged the reads. Another way to prevent reads from Firestore rules is to store premiumUntill in Custom Claims. You'll require a Cloud Function to set custom claims but the best is you can then access premiumUntill from any other Firebase service such as storage and realtime DB if you use any.

在梵高的星空下 2025-02-04 08:24:13

计费是由文档读取的(或按成功查询)。使用get()还是其他都没关系。它仍然只是依赖文档的读物。没有其他方法可以检查以前的值或检查动态的东西。您将不得不为阅读付费。

有关更多信息,请检查此文档:

  • a href =“ https://firebase.google.com/docs/firestore/security/security/rules-scrupture#security_rule_rule_limits” rel =“ nofollow noreflow noreferrer”
  • < a href =“ https://firebase.google.com/docs/firestore/pricing#operations” rel =“ nofollow noreferrer”>读取,写入和删除

The billing is per document read (or per successful query). It doesn't matter if you use get() or other. It is still just one read of dependent document. There is no alternative way to check previous values or check something dynamic. You will have to pay for the reads.

For more information, check this documentations:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文