FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard. For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions. |
Missing field value
Solution
You need an index that specifies the target field in the index’s
terms
. This index lets you search for the target field value, and by
association, compute the list of documents that do not have that field
value.
This index lets us search for People
documents that contain a specific
degree in the degrees
field. See
Create documents
in the Index tutorials for the
definition of the People
documents.
Now we can query for the difference between all documents (via the
Documents
function) and the documents containing a "PhD" degree,
which results in the list of People
documents that do not have a
"PhD" degree:
{
data: [
{
ref: Ref(Collection("People"), "304065275331872256"),
ts: 1626238093630000,
data: {
first: 'Tim',
last: 'Cook',
age: 59,
degrees: [ 'BS', 'MBA' ],
letter: 'G'
}
}
]
}
{'data': [{'ref': Ref(id=304065277806510592, collection=Ref(id=People, collection=Ref(id=collections))), 'ts': 1626238095990000, 'data': {'first': 'Tim', 'last': 'Cook', 'age': 59, 'degrees': ['BS', 'MBA'], 'letter': 'G'}}]}
map[data:[map[data:map[age:59 degrees:[BS MBA] first:Tim last:Cook letter:G] ref:{304065246510712320 0xc0001805a0 0xc0001805a0 <nil>} ts:1626238066150000]]]
ObjectV(data: Arr(ObjectV(ref: RefV(id = "304065227032363520", collection = RefV(id = "People", collection = RefV(id = "collections"))),ts: LongV(1626238047580000),data: ObjectV(first: StringV(Tim),last: StringV(Cook),age: LongV(59),degrees: Arr(StringV(BS), StringV(MBA)),letter: StringV(G)))))
{data: [{ref: ref(id = "304065251711648256", collection = ref(id = "People", collection = ref(id = "collections"))), ts: 1626238071110000, data: {first: "Tim", last: "Cook", age: 59, degrees: ["BS", "MBA"], letter: "G"}}]}
{
data: [
{
ref: Ref(Collection("People"), "304065365448589824"),
ts: 1626238179570000,
data: {
first: 'Tim',
last: 'Cook',
age: 59,
degrees: [ 'BS', 'MBA' ],
letter: 'G'
}
}
]
}
Discussion
When Fauna indexes a field containing an array value, one index entry per array item is created. That makes it straightforward to query for a single item in the array.
The Difference
function is used to list the difference between
all of the documents in the collection (via the Documents
function) and the documents that have the "PhD" degree by using the
index.
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!