Here is the code snippet I've been working on:
let addSubmissions = await Submission.find({"type": "add-information"}, (err) => {
if(err) {
console.log(err)
req.flash('error', 'No "add submissions" were found')
res.redirect('/admin')
}
})
for(let addKey in addSubmissions) {
let currentAddSubmissionAircraft = addSubmissions[addKey].aircraft
let addSubmissionAircraft = await Aircraft.findById(currentAddSubmissionAircraft, {name: 1}, (err) => {
if(err) {
console.log(err)
req.flash('error', 'No aircraft was found with the given ID')
res.redirect('/admin')
}
})
addSubmissions[addKey].aircraft = addSubmissionAircraft.name
}
I have a situation where I am retrieving submissions from the Submission collection in MongoDB and storing them in the variable 'addSubmissions'. One of the fields within these submissions is 'aircraft' which holds an id referencing another collection called 'aircrafts'.
Within the loop, I am trying to fetch the aircraft object using the id stored in the 'aircraft' field of each submission and replace it with the name of the aircraft. However, despite my efforts, the object does not seem to be updated as expected.
Any insights on why this might be happening?
Thank you :)