Google cloud firestore Firestore规则:仅当文档字段为false时显示文档

Google cloud firestore Firestore规则:仅当文档字段为false时显示文档,google-cloud-firestore,firebase-security,Google Cloud Firestore,Firebase Security,我有一个NSFW系统,它会检查文档是否为NSFW,如果是,它会将文档字段isNSFW更新为true。这很好,但现在我不想通过设置规则向所有用户显示这些文档,而不是查询出来 这就是我所拥有的,但它不起作用。。。 javascript service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if

我有一个NSFW系统,它会检查文档是否为NSFW,如果是,它会将文档字段
isNSFW
更新为
true
。这很好,但现在我不想通过设置规则向所有用户显示这些文档,而不是查询出来

这就是我所拥有的,但它不起作用。。。 javascript

service cloud.firestore {
    match /databases/{database}/documents {
        match /{document=**} {
            allow read, write: if request.auth.uid != null;
        }
    }
    match /users/{user} {
        allow read: if true;
    }
    match /docs/{doc} { // THIS HERE
        allow read: if resource.data.isNSFW == false; 
    }
}
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // match /{document=**} {
    //  allow read, write: if request.auth.uid != null;
    // }
    match /users/{user} {
        allow read: if currentUser().uid != null;
    }
    match /docs {
      allow read: if existingData().users[currentUser().uid] == false; 
    }
    match /docs/{doc} {
      allow write: if currentUser().uid != null;
    }
  }
  // MARK - Funcs ---------------
  function existingData() {
    return resource.data
  }

  function incomingData() {
    return request.resource.data
  }

  function currentUser() {
    return request.auth
  }

  function isSignedIn() {
    return request.auth != null;
    }
}
我尝试在
资源之前添加
请求。
,但仍然不起作用

更新: javascript

service cloud.firestore {
    match /databases/{database}/documents {
        match /{document=**} {
            allow read, write: if request.auth.uid != null;
        }
    }
    match /users/{user} {
        allow read: if true;
    }
    match /docs/{doc} { // THIS HERE
        allow read: if resource.data.isNSFW == false; 
    }
}
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // match /{document=**} {
    //  allow read, write: if request.auth.uid != null;
    // }
    match /users/{user} {
        allow read: if currentUser().uid != null;
    }
    match /docs {
      allow read: if existingData().users[currentUser().uid] == false; 
    }
    match /docs/{doc} {
      allow write: if currentUser().uid != null;
    }
  }
  // MARK - Funcs ---------------
  function existingData() {
    return resource.data
  }

  function incomingData() {
    return request.resource.data
  }

  function currentUser() {
    return request.auth
  }

  function isSignedIn() {
    return request.auth != null;
    }
}
获取错误:

Listen for Query(docs where users.`40S88coPQObEWSeiYMZIJlIKJkI2` == false order by __name__) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}

您的匹配项嵌套不正确。它们应该位于以
match/databases/{database}/documents
开头的块中。此外,您应该强烈考虑在<代码> / {文档=**} /COD>中删除匹配,因为这将允许每个人在登录时忽略数据库中的任何文档,忽略所有其他规则。

< P>如果您使用FielBaseDATASORE,您可以简单地查询数据:

var myDB=db.collection(“YOUR-db-collection”);
var query=myDB.where(“isNSFW”,“=”,false);
如果您使用的是GCP数据存储,则可以采用其他方式:

const query=数据存储
.createQuery('YOUR-COLLECTION')
.filter('isNSFW','=',false);

如果没有看到您的代码,就无法确定它为什么不工作。但请记住:规则本身并不是过滤器。您的代码还需要显式查询
isNSFW
false
的文档。侦听查询(用户所在的文档。
40S88coPQObEWSeiYMZIJlIKJkI2
==false按名称排序)失败:状态{code=PERMISSION\u DENIED,description=缺少或权限不足,cause=null}