为什么不将数据加载到我的集合中? mongodb

发布于 2025-01-26 13:50:01 字数 700 浏览 1 评论 0原文

这就是我的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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清浅ˋ旧时光 2025-02-02 13:50:01

使用insertone而不是创建用于插入数据库中的

官方doc 站点

use insertOne instead of create for inserting in the database

here is the official doc site

◇流星雨 2025-02-02 13:50:01

您配置了身体解析器吗?如果不是,它可能会导致上述问题:

步骤1:

npm安装Body-Parser

步骤2:在您的index.js file或server.js文件中:

const bodyParser = require('body-parser');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

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 :

const bodyParser = require('body-parser');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文