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

2024-01-29

I am 来自这个问题 https://stackoverflow.com/q/48795711/6509751。我想过开始对它进行赏金,因为它已经几个月没有受到任何关注,而且随着时间的推移我没有看到任何答案,但我认为我的愿望有点不同。

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

有问题Firestore规则 https://firebase.google.com/docs/firestore/security/get-started arises.

像这样的检查变得不可能:

resource.data.number > 11

It is 不可能比较strings就好像他们是ints.

The 模拟器例外情况如下:

Unsupported operation error. Received: string > int. Expected: constraint > constraint, int > int, float > float, duration > duration, timestamp > timestamp, constraint > any, any > constraint. 

有没有办法将我的操作转换为int > int?


查看这个链接 https://firebase.google.com/docs/reference/rules/rules.Integer它向您展示了如何在 Firestore 规则文档中将字符串转换为整数。

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

所以你的支票可能是:

int(resource.data.number) > 11
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Cloud Firestore 安全规则中将字符串转换为 Int 的相关文章

随机推荐