-1

I want to retrieve all the datas from my mongo db collection "Assets" whose "chapterName" is equal to the string sent through the url, How to get it?

app.get(`/api/assets/get_all/${chapterName}`, (req, res) => {
  Assets.find({}, (err, assets) => {
    if (err) return res.status(400).send(err);
    res.status(200).send(assets);
  });
});
LoGan
  • 97
  • 4
  • 13
  • What is your problem *exactly*? Have you tried looking at similar posts in stack overflow? – oneturkmen Nov 23 '19 at 20:17
  • Does this answer your question? [How to query MongoDB with "like"?](https://stackoverflow.com/questions/3305561/how-to-query-mongodb-with-like) – Paulo Tomé Nov 23 '19 at 20:31

1 Answers1

0

the chapterName will be in params of request, req. let's say chaptername is present in mongoose schema.

app.get('/api/assets/get_all/:chapterName}', (req, res) => {
  Assets.find({ chaptername: req.params.chapterName }, (err, assets) => {
    if (err) return res.status(400).send(err);
    res.status(200).send(assets);
  });
});
prisar
  • 3,041
  • 2
  • 26
  • 27