2

In Firestore, I have documents that have fields that may or may not be null. If there are indeed holding a null value, I'd like to write on them. If not, I don't want to write to them.

Is there a way to do this without checking it before updating it?


Note: I am operating on Firebase Cloud Functions.

Xevion
  • 570
  • 5
  • 17

2 Answers2

0

Good idea to use FireStore Rule Condition for write (update) action. https://firebase.google.com/docs/firestore/security/rules-conditions

Try to set SKIP if field exist

-1

Writing to a document requires that you know its full path. And the only way to know the full paths of the documents with the relevant value is to perform a query for those documents. So no, there's no way to update all documents that meet a specific condition without first querying for them, and thus incurring the read cost.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    I think the question was not about updating every document with null value in them but more only updating a value if the value is null. – Julien Sanchez Jun 16 '22 at 21:52