You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately this is expected behavior and there isn't much Mongoose can do about it because you're using lean(). The MongoDB driver stores buffers as MongoDB's Binary type. Mongoose converts MongoDB Binary objects into Buffers based on your schema. But we don't do that if you use lean(), because the whole point of lean() is to avoid schema conversion to minimize performance overhead..
TLDR:
server.get('/getImageWithLean',async(req,res)=>{constfile=awaitfileModel.findOne({}).lean();if(file==null){res.sendStatus(400).send();return;}res.contentType(file.mimetype);// Pull out the underlying buffer from the MongoDB Binary instanceres.send(file.content.buffer);});
Hi,
I have this model:
I return
content
field with this code in Nest js framework:When I find document with this code:
It's OK.
but when I use .lean() function in findById Or findOne and return image to client, Image is not valid image file!
I use:
MongoDb cloud v 4.0.
mongoose: ^5.5.7
@nestjs/mongoose: ^6.1.2,
thanks.
The text was updated successfully, but these errors were encountered: