[英]Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters, its in mongodb and node
enter image description here I am trying to do a get request for each blog when they are clicked but for some reason its not working am getting an error.在此处输入图像描述我正在尝试在单击每个博客时对它们进行获取请求,但由于某种原因它无法正常工作,因此出现错误。 Here is my code.
这是我的代码。
<% blogs.forEach(blog => { %>
<a href="/blogs/ <%= blog._id %> ">
<h3> <%= blog.title %> </h3>
<p> <%= blog.snippet %> </p>
</a>
<% }) %>
<div class="details content">
<h2> <%= blog.title %> </h2>
<div class="content">
p> <%= blog.body %> </p>
</div>
</div>
app.get('/blogs/:id', (req,res) => {
const id = req.params.id;
Blog.findById(id)
.then(result => {
res.render("details", {blog: result});
})
.catch(err => {
console.log("Error", err);
})
})
just try like this试试这样
const bodyParser = require('body-parser');
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.