[Vuejs]-Can i add mongodb _id to localhost adress to display one post from database?

0👍

Number 1: http://localhost:5000/api/posts/6061890d59ec3b6abcb011fb is correct, but you’re going to need to create a new route to handle that request.

These are often called ‘show’ routes.

router.get("/:id", async (req, res) => {
  // code to handle the logic of that request
  // access the url parameter via: req.params.id
});

0👍

router.get("/:id", async (req, res) => {
  const posts = await loadPostCollection();
  res.send(await posts.findOne({
    _id: req.params.id,
  }));
});

Leave a comment