firestore规则路径的大小

tha*_*ffe 6 firebase google-cloud-firestore

我试图在 firestore 规则中使用路径的大小,但无法让任何东西起作用,并且在 firestore 文档中找不到有关如何执行此操作的任何参考。

我想使用最后一个集合名称作为规则中的参数,所以尝试了以下方法:

match test/{document=**}
   allow read, write: if document[document.size() - 2] == 'subpath';
Run Code Online (Sandbox Code Playgroud)

但 .size() 似乎不起作用,.length 也不起作用

Boh*_*ukh 1

您可以在这里学习规则

   // Allow reads of documents that begin with 'abcdef'
   match /{document} {
      allow read: if document[0:6] == 'abcdef';
   }
Run Code Online (Sandbox Code Playgroud)

  • 这并不能解决我遇到的问题。我正在使用多段通配符“{document=**}”。我设法发现它是由多个路径构成的,因此您可以执行 document[0] 来获取第一个路径参数。但我想取出倒数第二个路径参数`document[document.size() - 2]`,所以需要知道多段通配符路径的大小,但是`.size()`不起作用 (3认同)