Lets say I have a bunch of documents of type CONTACT:
{
"contactId": "V1234",
"contactFirstName": "A",
"contactLastName": "N",
"emailAddress": "12345",
"invitationId": "IVT:123",
"documentType": "CONTACT"
}
And for each contact document there is a EMAIL document and an INVITATION document:
EML:12345
{
"emailId": "12345",
"emailAddress" = ["abc@gmail.com"]
}
IVT:123
{
"invitationId": "IVT:123",
"invitationStatus": ["REGISTERED"]
}
Lets say I have an array of contactIds : ["V1234", "V2345" ... ]
How would I write a SELECT
query for each contactId in that list and select contactFirstName
, contactLastName
, eml.emailAddress.[0]
, invitation.status.[0]
(only if the status is of type "REGISTERED"
, or "INVITED"
.) and limit it to 10 values.
I was thinking something like:
SELECT DISTINCT
contact.contactFirstName as `contactFirstName`,
contact.contactLastName as `contactLastName`,
eml.emailAddress as `emailAddress`,
ivt.status[0].status AS invitationStatus
from
`contact-services` AS contact
INNER JOIN `contact-services` AS eml ON
CONCAT("EML",':',contact.contactEmailAddressIds[0]) =meta(eml).id
INNER JOIN `contact-services` AS ivt ON
contact.invitationId =meta(ivt).id
WHERE
contact.documentType="PERSON_CONTACT"
AND
ivt.status[0].status IN ["INVITED", "REGISTERED"]
and
contact.contactId IN ["V8459243"]