I am using the xdmp.eval function to search and return a document in my final database to use during my harmonization process.
let finalDoc = xdmp.eval(
"fn.head(cts.search(cts.jsonPropertyValueQuery('Id',id,
['exact']),['unfiltered','score-zero']))",
{'id':id},
{"database" : xdmp.database("data-hub-FINAL")});
The document is returned as a sequence with this structure:
{"SourceSystemName":"",
"BatchDtTm":"06/20/2018 15:05:15",
"SubjectArea":"Customer",
"DocumentType":"Registration",
"Id":"100",
"Contact":[
{"CustomerId":"1",
"FirstName":"",
"LastName":"",
"EmailId":""
},
{"CustomerId":"2",
"FirstName":"",
"LastName":"",
"EmailId":""
}
]
}
I need to iterate through each customer in the Contact array using finalDoc.Contact.forEach(). However, when I use fn.head(finalDoc.toArray()) or fn.head(finalDoc.toObject()) to change the finalDoc sequence to an array, my forEach function fails with the error "Cannot read property 'forEach' of undefined". When I simply just try to output the contact array by doing finalDoc.Contact (or finalDoc[0].Contact), I get a "Null" output.
How do I grab the Contact array out of the sequence and iterate through it using forEach? Thanks!