【发布时间】:2021-09-03 21:17:07
【问题描述】:
我有一个如下的猫鼬图像架构:
const ImageSchema = new mongoose.Schema({
img:
{
data: Buffer,
contentType: String
}
})
mongoose.model('Image',ImageSchema)
和章节架构
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)
我会为图片做人口统计
Chapter.find()
.populate({
path:"u_img",
select:["img"]
})
.exec(function(err,chapters){
if(err) res.send(err)
res.send(chapters)
})
我正在尝试将本章中每个图像的缓冲区转换为 base64string。 有人可以帮我吗?有没有办法在猫鼬中对填充函数进行转换?或者我必须在 exec func 中映射并进行转换?还是有其他方法?
【问题讨论】:
标签: javascript node.js express mongoose mongoose-populate