I have a mongoose Image Schema as below:
const ImageSchema = new mongoose.Schema({
img:
{
data: Buffer,
contentType: String
}
})
mongoose.model('Image',ImageSchema)
and a Chapter schema
const chapterSchema = new mongoose.Schema({
chapter_no:{ type: Number, min: 0, max: 50 },
published:Boolean,
u_img:{type:mongoose.Schema.Types.ObjectId, ref:"Image"}
})
mongoose.model('Chapter', chapterSchema)
I'll do population for the image
Chapter.find()
.populate({
path:"u_img",
select:["img"]
})
.exec(function(err,chapters){
if(err) res.send(err)
res.send(chapters)
})
and I'm trying to convert the buffer to base64string for every single image in the chapter. Could anyone please help me? is there a way to do conversion on populate function in mongoose? or I have to map and doing conversion inside the exec func? or is there another way?