【问题标题】:Firestore orderBy security ruleFirestore orderBy 安全规则
【发布时间】:2018-08-27 16:45:56
【问题描述】:

我刚刚开始使用 Firestore,正在尝试创建一个安全规则来支持来自我的应用 (Android/kotlin) 的这种查询

firestoreDb.collection("messages").whereEqualTo("room_id", "c_1")
    .orderBy("timestamp", Query.Direction.ASCENDING)

我的数据库结构是:

room
   -{roomId}
      -members [] //this is an array of strings
messages
   -{messageId}
      -timestamp
      -room_id
      -message_text

安全规则如下:

service cloud.firestore {
  match /databases/{database}/documents {
    match /messages/{messageId} {
        allow read: if request.auth.uid in get(/databases/$(database)/documents/rooms/$(resource.data.room_id)).data.members && 
        request.query.orderBy == "timestamp"
    }
  }
}

如果我不使用 orderBy 部分,一切正常,并且我得到了成功的响应。但是,在代码中应用 orderBy 之后,我需要将 orderBy 规则添加到 firestore 安全规则中。不幸的是,我找不到任何语法示例,应该如何定义。

这是我用作参考的official documentation,但只有request.query.limit 的示例,尚不清楚request.query.orderBy 应该如何工作。

非常感谢任何帮助 干杯

【问题讨论】:

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


    【解决方案1】:

    抱歉回复晚了。

    我们应该认为 request.query.orderBy 有 Map。

    request.query.orderBy.timestamp == 'ASC'
    

    【讨论】:

    • 降序查询会是什么?
    猜你喜欢
    • 2018-10-19
    • 2019-07-05
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多