18.05.2016 Views

Mittwoch, 18. Mai, 2016

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MongoDB CRUD the MVC way with Passport Authentication 58<br />

postmanSuccess<br />

Important to note is that in my case (with Postman) I had to add the Content-Type header<br />

(application/json) manually for the request.<br />

Find all users<br />

Great, so you created a new user in the users collection. In order to list existing users add the<br />

following code to your app/controllers/user.server.controller.js file:<br />

1 exports.list = function(req, res, next) {<br />

2 User.find({}, function(err, users) {<br />

3 if (err) {<br />

4 return next(err);<br />

5 }<br />

6 else {<br />

7 res.json(users);<br />

8 }<br />

9 });<br />

10 };<br />

Now you need to set up a route for this new method and in order to do so, go to your<br />

app/routes/users.server.routes.jsfile and change the app.route line to:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!