skip to Main Content

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


  1. I tried to reproduce the problem you have, but it seems to work as expected for me here:

    enter image description here

    You can see that my test76141403 function returns true here, because the doc at /not/existing does not exist. If I change the test to !=, the same function returns false.

    Login or Signup to reply.
  2. This is a Firestore bug: https://github.com/firebase/firebase-tools/issues/2067

    Use this instead:

    function safeget(path) {
       return exists(path) ? get(path) : null;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search