const images = await tbl
.find({
creator_id: req.user._id,
})
.select({
creator_id: 0,
})
.then((images) =>
images.forEach((image) => {
image.file_name = process.env.IMAGE_HOST_URL + image.file_name;
})
);
The code above fails at the .then bit.
What is the proper mongoose method to replace it with to achieve what is intended in the code?
What do you mean fails?
The find returns two objects. An err and res. the .then should be
.then((err, res) => {
if (err) {...}
else {
res.forEach(img => {
image.file_name = process.env.IMAGE_HOST_URL + image.file_name;
img.save()
})
}
})
You will get a list of documents that match the filter of the find as the res (error object, which should be null, is first). And you must save it after the changes.