首页 > 解决方案 > 嵌套的 Firestore 安全规则 - get()

问题描述

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

// 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-firestorefirebase-security

解决方案


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

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


推荐阅读