【问题标题】:Cloud firestore rules - get document by it's field valueCloud Firestore 规则 - 通过它的字段值获取文档
【发布时间】:2018-12-11 17:07:22
【问题描述】:

我有两个集合worktimessubmissions。提交文件有 uid 字段。 我希望能够在未签名时更新/删除工作时间文件。我想要这样的东西:

match /worktimes/{document=**} {
  allow update, delete: if !isMonthSigned()
} 

在我的 isMonthSigned() 我想查看提交集合,选择 uid 等于我的文档,然后可以访问它的字段值。我如何获得该文件? 到目前为止,我被困在这里:

get(/databases/$(database)/documents/submissions/{submission})

谢谢!

【问题讨论】:

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


    【解决方案1】:
        service cloud.firestore {
          match /databases/{database}/documents {
            function isSignedIn() {
              return request.auth != null;
            }
    
            function isOwner(userId) {
              return request.auth.uid == userId
            }
    
    
            match /submissions/{submission} {
              allow update, delete: if isSignedIn()
                && isOwner(resource.data.userId);
           }
    
         }
       }
    

    【讨论】:

    • 我应该澄清一下 isMonthSigned() 应该检查提交文件中的uid是否等于我的uid,提交文件中的月份字段是否等于工作时间文件中的月份字段。
    • 分享firestore节点的快照
    猜你喜欢
    • 2018-09-29
    • 2023-02-13
    • 1970-01-01
    • 2018-06-03
    • 2020-06-09
    • 2018-07-04
    • 2019-08-26
    • 1970-01-01
    • 2021-11-19
    相关资源
    最近更新 更多