I have docs for contacts which have an array of docs called emails. The blow gets the the farm who has an email which matches my clause. But it does not only return the email element with the address match but all emails for the farm that has a doc with the matching email.
So how can i limit the return to only the email doc in array which also matches the e.address ?
select c.emails from Contacts c
where c._type= "farm" AND ANY e IN c.emails SATISFIES e.address = 'user@bellsouth.net' END;
select ARRAY e FOR e IN c.emails WHEN e.address = 'user@bellsouth.net' END AS emails
from Contacts c
where c._type= "farm" AND ANY e IN c.emails SATISFIES e.address = 'user@bellsouth.net' END;
select FIRST { e.id, e.bounce} FOR e IN c.emails WHEN e.address = 'user@bellsouth.net' END AS emails
from Contacts c
where c._type= "farm" AND ANY e IN c.emails SATISFIES e.address = 'user@bellsouth.net' END
;
Post exact query the query earlier post doesn’t produce this results.
select RAW FIRST { e.id, e.bounce} FOR e IN c.emails WHEN e.address = 'user@bellsouth.net' END
from Contacts c
where c._type= "farm" AND ANY e IN c.emails SATISFIES e.address = 'user@bellsouth.net' END;
select e.id, e.bounce
from Contacts c
UNNEST c.emails AS e
where c._type= "farm" AND e.address = 'user@bellsouth.net';
select raw array { e.id, e.bounce}FOR e IN c.emails WHEN e.address = myEmail END AS email
from Contacts c LET myEmail = 'user@bellsouth.net'
where c._type= "farm" AND ANY e IN c.emails SATISFIES e.address = myEmail END;
Yes , with the INNEST i can get it done but i had the issue with the e In selection. So let me ask this, is there a rule of thumb when to use what ? Also if so does either have a huge speed benefit ?
UNNEST is self JOIN between original document with each array element, will expand documents and can be slow. If you need to select the array elements you must use unnest. Or reconstruct and you get ARRAY.
select e.id, e.bounce
from Contacts c
UNNEST c.emails AS e
where c._type= "farm" AND e.address = 'user@bellsouth.net';