在Cloud Firestore安全规则中将字符串转换为Int

时间:2018-06-22 14:58:14

标签: firebase google-cloud-firestore firebase-security-rules

我是coming from this question。我考虑过要对其进行赏金,因为它已经几个月没有受到任何关注,并且随着时间的推移,我没有看到任何答案,但是我认为我的愿望有所不同。

如果有一个数字作为文档的字段,但指定为string

screenshot

出现Firestore Rules的问题。

这样的检查变得不可能:

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

1 个答案:

答案 0 :(得分:3)

签出this link,向您展示如何在Firestore规则文档中将字符串转换为整数。

int("2") == 2
int(2.0) == 2

所以您的支票可能是:

int(resource.data.number) > 11
相关问题