Query flags
Even with the addition of !=
to Firestore, the approach familiar to all SQL developers, where you check for a null
value, is still impossible.
To make such a query possible:
You would have to add query flags that denote the state. Consider this example where you have a soft deletion feature implemented using field groups:
To make it work, in addition to the at
and by
fields, you would need to add a deleted
flag solely to make the query possible:
It is even trickier to select all non-deleted posts, as Firestore’s !=
operator excludes documents where the field does not exist, so you have a couple of options.
The first option is to make the deleted
field required and union with false
, allowing you to query for non-deleted posts:
Another option is to use a state field group:
Depending on your use case, you might want to use one or another approach. The first one is more flexible and allows for the addition of more state combinations. In contrast, the second one is more uniform and forces one state field, which might be easier to work with.