FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. For more details, review the migration guide. Contact support@fauna.com with any questions. |
Null field
Problem
You want to find documents where specific fields have Null values, even though Fauna does not store fields with Null values.
Solution
Create an index that includes a
binding. The binding can reflect
the state of a field even if that field was set to null
and is not stored:
This index is based on the Letters
documents created in the
Index tutorials.
With that index, it is easy to find the documents where the has_extra
binding is false
:
{
data: [
[ 'M', Ref(Collection("Letters"), "113") ],
[ 'Z', Ref(Collection("Letters"), "126") ]
]
}
{'data': [['M', Ref(id=113, collection=Ref(id=Letters, collection=Ref(id=collections)))], ['Z', Ref(id=126, collection=Ref(id=Letters, collection=Ref(id=collections)))]]}
map[data:[[M {113 0xc00007f9b0 0xc00007f9b0 <nil>}] [Z {126 0xc00007fb60 0xc00007fb60 <nil>}]]]
ObjectV(data: Arr(Arr(StringV(M), RefV(id = "113", collection = RefV(id = "Letters", collection = RefV(id = "collections")))), Arr(StringV(Z), RefV(id = "126", collection = RefV(id = "Letters", collection = RefV(id = "collections"))))))
{
data: [
[ 'M', Ref(Collection("Letters"), "113") ],
[ 'Z', Ref(Collection("Letters"), "126") ]
]
}
Discussion
Fauna does not store fields with null
values, which is a storage
optimization to prevent needless storage costs. That means that for
documents you create where a field value was set to null
, it is as if
the field was never specified.
When you use the Match
function, the provided value(s) can never match
fields that are not stored.
Index bindings execute when an index entry is created or updated, so
that the computed value can be stored along with the index’s values
fields. This means that the has_extra
binding’s result accurately
reflects whether the indexed document has an extra
field.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!