firebase Firestore规则- get()行为(bug?)

wnavrhmk  于 2023-05-01  发布在  其他
关注(0)|答案(2)|浏览(182)

在Firestore规则中,我创建了这个函数:

function rulesTest() {
     let doc = get(/databases/$(database)/documents/someCollection/someDocId);
     return doc == null;
}

根据get()方法的文档,它的返回类型是:

非空规则。firestore.resource文档,如果文档不存在,则为null

在一个空的数据库上测试这个函数(所以没有someCollectionsomeDocId),我希望doc为null,因此rulesTest()返回true
实际返回类型为false

奇怪的是

即使我将return语句更改为return doc != null,函数也会返回false

edit:这是在Emulator上发生的

hujrc8aj

hujrc8aj1#

这是一个Firestore bug:https://github.com/firebase/firebase-tools/issues/2067
使用这个代替:

function safeget(path) {
   return exists(path) ? get(path) : null;
}
qoefvg9y

qoefvg9y2#

我试图重现您遇到的问题,但它似乎在这里为我工作:

您可以看到我的test76141403函数在这里返回true,因为/not/existing处的文档不存在。如果我将测试更改为!=,则相同的函数将返回false

相关问题