I am running into some data consistency issues for example i have a query which uses the following part
ARRAY {lower(v.type):v.\
address`} FOR v IN f.emails END AS emails,`
to create an Array based on type and address. My problem now is if i have some docs which have a number but no type
element this query will not return anything. Is there a way to change it lets say if v.type is null or not present we use “default” otherwise we use the actual value of v.type
Update i was able to figure out a work around for the first question.
ARRAY {CASE WHEN v.type IS NOT MISSING THEN v.type
ELSE "default"
END :v.`address`} FOR v IN f.emails END AS emails,
Also how can i update all arrays in my docs to add a type = “default” to it. I know how to get all records who match the criteria .
select c.emails, e.id from Contacts c
UNNEST c.emails e
where c._type= "farm" and ARRAY_COUNT(c.emails) > 0 and e.type IS MISSING
this returns me all emails arrays which have data and no type set.
And here is the working version of updating the phones array doc with type = default if it did not exist
UPDATE `Contacts` c
SET p.type = "default" FOR p IN c.phones END
where c._type= "farm" and ARRAY_COUNT(c.phones) > 0