在猫鼬中创建新文档的问题

时间:2021-04-11 12:11:56

标签: node.js mongodb mongoose

我想用猫鼬添加一个新文档 但它只创建 _id 没有我输入的所有细节 在邮递员我输入: { "name":"jhon", "email":"jhon11@gmail", “密码”:“1234” } 但在资源中得到了这个: { "_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,
}

})

感谢您的建议。

0 个答案:

没有答案