Google cloud firestore Firestore安全规则获取()问题

Google cloud firestore Firestore安全规则获取()问题,google-cloud-firestore,firebase-security,Google Cloud Firestore,Firebase Security,我正在尝试为firestore DB编写一个安全规则,但由于某些原因遇到了问题。下面代码中的语法对任何人来说都是错误的吗 match /posts/{postType} { allow read: if true; allow write: if get(/databases/$(database)/documents/posts/$(postType)).data.creator_id == request.auth.uid; } 我附上了路径和

我正在尝试为firestore DB编写一个安全规则,但由于某些原因遇到了问题。下面代码中的语法对任何人来说都是错误的吗

match /posts/{postType} {
  allow read: if true;
  allow write: if get(/databases/$(database)/documents/posts/$(postType)).data.creator_id == 
                  request.auth.uid;
}
我附上了路径和数据结构的截图。我遇到的问题是“get”返回null

数据和路径:

错误:

您必须更改规则

而不是:

allow write: if get(/databases/$(database)/documents/posts/$(postType)).data.creator_id == request.auth.uid;

你必须写:

allow write: resource.data.creator_id == request.auth.uid;

request.resource.data.creator\u id==request.auth.uid
就是解决方案

您没有正确使用模拟器。当要求输入要获取的文档的路径时,您必须提供指向实际文档的路径。不要从匹配中键入通配符。这些规则将在计算规则时确定通配符的实际值。如果您输入“/posts/{postType}”,您会告诉它直接加载ID为“{postType}”的文档,而该ID并不存在。

当您尝试使用这些规则时,具体会出现什么问题?如果不查看执行查询的代码和实际文档数据,安全规则本身就没有任何意义。请编辑问题,以显示查询代码和未按预期方式工作的数据库数据。问题中应该有足够的信息,以便任何人都可以重现这个问题。对不起,我只是编辑了这个问题以显示数据和错误。我正在使用规则模拟器进行查询。资源为我返回空值?我给它的路径是/posts/{postType}。假设我想允许它们在/posts/{postType}等于request.auth.uid的情况下写入postsType的子集合?我假设一旦我可以做第一个,子集合应该只需要正确的路径。我只是不知道如何使用{postType}变量。好的。从您添加的屏幕截图中,我可以看到在使用规则操场时出现了错误。在规则操场上,他们询问您输入的位置
/posts/{postType}
,在
{postType}
位置,您必须将其替换为数据库中已有的documentID。例如:
efsfes
是我的文档ID,那么在位置中它必须是
/posts/efsfes