July 2019
Intermediate to advanced
416 pages
10h 6m
English
With the Picture model available to us, we can populate it directly from inside our add route. The request body contains the same parameters as our schema, so the mapping is invisible to us. When it has been populated, we call the save method. If there's an error, we will send this back to the client; otherwise, we are going to send the picture back to the client:
const picture = new Picture(request.body);picture.save((err, picture) => { if (err) { response.send(err); } response.json(picture);});