In Firestore rules I created this function:
function rulesTest() {
let doc = get(/databases/$(database)/documents/someCollection/someDocId);
return doc == null;
}
According to the documentation of the get() method the return type of it is:
non-null rules.firestore.Resource the document, or null if it does not
exist
Testing this function on an empty database (so no someCollection
and no someDocId
) I am expecting doc to be null and therefore rulesTest()
to return true
.
Actual return type is false
.
The weird part:
Even if I change the the return statement to return doc != null
the function would return false
.
edit: This is happening on Emulator
2
Answers
I tried to reproduce the problem you have, but it seems to work as expected for me here:
You can see that my
test76141403
function returnstrue
here, because the doc at/not/existing
does not exist. If I change the test to!=
, the same function returnsfalse
.This is a Firestore bug: https://github.com/firebase/firebase-tools/issues/2067
Use this instead: