MEAN堆栈应用程序 – 通过userId查询

我已经使用NodeJS和Express构build了一个将GET和POST值添加到数据库(MongoDB)的API。

我只能通过userid(localhost:3000 / comments / userid / 3)

但是我想获得一个用户的所有评论

/* 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); }) }); 

有没有办法做到这一点? 像findOne方法一样?

只要find与查询

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