首页 > 解决方案 > 在猫鼬中创建新文档的问题

问题描述

我想用猫鼬添加一个新文档,但它只创建 _id 没有我在我输入的邮递员中输入的所有详细信息:{ "name":"jhon", "email":"jhon11@gmail", "password" :"1234" } 但在 res: { "_id": "6072e8d3f0f69037cc05b8cb", "__v": 0 }

我的代码:

const addUser = async (req, res) => {
try {
    let user = new User(req.body)
    await user.save()
    res.send(user)

}
catch (error) {
    res.status(400).send(`error ${error}`)
}

}

架构是:

const userSchema=mongoose.Schema({
name:{
    Type:String
},
email:{
    Type:String
},
password:{
    Type:String,
}

})

感谢您的任何建议。

标签: node.jsmongodbmongoose

解决方案


推荐阅读