So I have the following code:
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 get all the submissions from the Submission collection in MongoDB and assign them to the addSubmissions variable. One of it's fields is 'aircraft' and it's value is an id from another collection called 'aircrafts'.
In the for loop I search the aircraft with the 'aircraft' field (which is the id) from the submissions and I want to change the value of 'addSubmissions.aircraft' from the id to the name of the aircraft.
For some reason the object is not changing.
Any idea why?
Thanks :)