I have a collection with a document containing data in an array, i want to loop through this array and get data from each element.
Document A:
{
"_id": "mthjL06DgJNiwr6lIf",
"name": "KID1",
"id": [
"zAxNarwAE2AnvPb8P",
"me3AWg85YDvWMShKY",
"DaX7d98X42zXmlAqW",
"wZkLkApk857QklApo"
],
"hardware": "5",
}
Document B:
{
"_id": "zAxNarwAE2AnvPb8P",
"emails": [
{
"address": "hotel@hey.oh",
"verified": false
}
], "name": "Jean-Paul"
}
So what i want to do is to loop thourgh the first document A, and with id, i do a research on my database to get emails.adresses and firstname from document B.
At the moment i can get all the emails from the first document don’t know how combine both the task.
to go through the DOCUMENT A and get one by one the senders and get their firstname and emails ?
my code :
Testg:{
type: new GraphQLList(Kid),
resolve: async (_, args, { userId }) => {
if (!userId) {
throw new Meteor.Error(401, 'Unauthorized');
}
const sendersIterable = []
const kids = await Kids.find({ "senders.0": userId})
kids.forEach((kid) => {
sendersIterable.push({
_id: kid._id,
name: kid.name,
email:kid.senders
})
for (i of Senders){
const user = Meteor.users.findOne({_id: userId },{ emails: 1, profile: 1 })
return {
firstname:user.profile.name,
email:user.emails[0].address
}
}
})
return sendersIterable
}
},