Sunday, 2 April 2017

MEAN stack application - querying by userId

I have built an API to GET and POST values into a database(MongoDB) using NodeJS and Express.

I am able to get only a single comment by the userid (localhost:3000/comments/userid/3)

But I want to get all comments by a single user

/* GET /comments/userid/userid */
router.get('/userid/:userid', function(req, res, next) {
  Comments.findOne({userId:req.params.userid}, function (err, post) {
    if (err) return next(err);
    res.json(post);
    })
});

Is there any method to do this? Like the findOne method?



via Dilinieee

No comments:

Post a Comment