My goal is to send back the "projets" array within an expressJs route after fetching images for each item. However, when I return the response with the updated array, the newly added fields don't seem to be included.
Note: When I log the added item, it displays correctly with the updated information.
var projets = await Annonce.find(
{ type_annonce: { $ne: "bien" }, deleted_at: { $eq: null } },
null,
{ limit: 10, sort: { refreshed_at: -1 } }
);
for (let index = 0; index < projets.length; index++) {
var images = await Image.find({ BienID: projets[index]._id });
if (!images || images.length == 0) console.log("No images");
else {
projets[index].images = images;
}
}
console.log(projets[1].images);
response.json({ annonces: projets });