【问题标题】:Casting String to Int in Cloud Firestore Security Rules在 Cloud Firestore 安全规则中将字符串转换为 Int
【发布时间】:2018-06-22 14:58:14
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

    所以你的支票可能是:

    int(resource.data.number) > 11
    

    【讨论】:

    • 这实际上让我使用string() 等来进行类型安全操作:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 2019-07-19
    • 1970-01-01
    相关资源
    最近更新 更多