Updating the user model to store a photo in MongoDB

In order to store the uploaded profile photo directly in the database, we will update the user model to add a photo field that stores the file as data of the Buffer type, along with the file's contentType.

mern-social/server/models/user.model.js:

photo: {
data: Buffer,
contentType: String
}

An image file that's uploaded by the user from the client- side will be converted into binary data and stored in this photo field for documents in the Users collection in MongoDB. Next, we will look at how to upload the file from the frontend.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset