在Cloud Firestore安全规则中将字符串强制转换为Int [英] Casting String to Int in Cloud Firestore Security Rules
本文介绍了在Cloud Firestore安全规则中将字符串强制转换为Int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我来自这个问题.我考虑开始赏金,因为它已经几个月没有受到任何关注,并且随着时间的推移,我没有看到任何答案,但是我认为我的愿望有所不同.
I am coming from this question. I thought about starting a bounty on it because it has not received any attention in months and over the time I did not see any answers, but I think that my desire is a bit different.
如果有一个数字作为文档的字段,但指定为string
:
If there is a number as a field of a document, but specified as a string
:
出现 Firestore规则的问题.
这样的检查变得不可能:
Checks like this become impossible:
resource.data.number > 11
不可能将字符串当作是 ints 来比较.
模拟器异常如下:
Unsupported operation error. Received: string > int. Expected: constraint > constraint, int > int, float > float, duration > duration, timestamp > timestamp, constraint > any, any > constraint.
是否可以将我的操作转换为int > int
?
推荐答案
签出此链接,向您展示如何在Firestore规则文档中将字符串转换为整数.
Check out this link that shows you how to convert strings to integers in the Firestore rules docs.
int("2") == 2
int(2.0) == 2
所以您的支票可能是:
int(resource.data.number) > 11
这篇关于在Cloud Firestore安全规则中将字符串强制转换为Int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文