如何在不使用get()的情况下,根据父集合中的字段来控制Firestore子收集?
我在下面有此代码,但是在我的代码中导致额外的读取,我得到了数据集合中存储的值(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用
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 storepremiumUntill
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.计费是由文档读取的(或按成功查询)。使用
get()
还是其他都没关系。它仍然只是依赖文档的读物。没有其他方法可以检查以前的值或检查动态的东西。您将不得不为阅读付费。有关更多信息,请检查此文档:
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: