为什么不将数据加载到我的集合中? mongodb
这就是我的Mongo数据库中出现的内容:
这是我的应用程序。插入数据时,当我提交console console.log带有日期的对象,但使用创建它只是说“ null” - >
App listening on port 4000
{ '”title”': 'adaw', '”body”': 'dwdw' }
null { _id: new ObjectId("6274a7a58d8946ca10ae57c4"), __v: 0 }
app.post('/posts/store',(req,res)=>{
console.log(req.body)
BlogPost.create(req.body,(error,blogpost) =>{
console.log(error,blogpost)
res.redirect('/')
})
})`
This is what appears on my mongo database:
This is my app.post to insert the data, when I Submit it console.log the object with the dates but with create It just says "null" ->
App listening on port 4000
{ '”title”': 'adaw', '”body”': 'dwdw' }
null { _id: new ObjectId("6274a7a58d8946ca10ae57c4"), __v: 0 }
app.post('/posts/store',(req,res)=>{
console.log(req.body)
BlogPost.create(req.body,(error,blogpost) =>{
console.log(error,blogpost)
res.redirect('/')
})
})`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
insertone
而不是创建
用于插入数据库中的官方doc 站点
use
insertOne
instead ofcreate
for inserting in the databasehere is the official doc site
您配置了身体解析器吗?如果不是,它可能会导致上述问题:
步骤1:
npm安装Body-Parser
步骤2:在您的index.js file或server.js文件中:
Have you configured the body parser? If not, it may lead to the above problem:
Step 1 :
npm install body-parser
Step 2 : in your index.js file or server.js file :