【问题标题】:Nested Firestore security rules - get()嵌套的 Firestore 安全规则 - get()
【发布时间】:2018-10-07 09:30:18
【问题描述】:

有谁知道我是否可以创建嵌套的“获取”规则来访问数据库中的不同数据?怎么做?

// Assignment's document
match /assignments/{assignmentId} {
    function getAssignmentOwner(){
        return get(/databases/$(database)/documents/assignments/$(assignmentId)).data.owner;
    }
    function getAgencySupervisors(){
        return get(/databases/$(database)/documents/agencies/$(getAssignmentOwner())).data.supervisors;
    }

    allow write: if request.auth.uid in getAgencySupervisors();
    allow read: if request.auth != null;
}

目前它返回“不允许”。

【问题讨论】:

    标签: google-cloud-firestore firebase-security


    【解决方案1】:

    规则不是数据过滤器;您应该只对集合、文档或子集合使用规则,您不能使用规则来过滤文档内的结果。

    文档:https://firebase.google.com/docs/firestore/security/rules-structure

    【讨论】:

    • 如果我不嵌套它们就可以了。这有效:get(/databases/$(database)/documents/assignments/$(assignmentId)).data.owner;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2018-03-19
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多