Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content