node.js - 在猫鼬中创建新文档的问题
问题描述
我想用猫鼬添加一个新文档,但它只创建 _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,
}
})
感谢您的任何建议。
解决方案
推荐阅读
- javascript - 将文本文件中的特定文本插入 JavaScript 变量
- android - 如何从 React Native 中备份或导出 sqlite 数据库
- sql-server - 有没有办法让我查找并运行查询?
- reactjs - 我无法通过 Google Books API 的响应更新状态
- sql-server - SQL Server 安装后没有运行甚至显示的 SQL 服务
- python - Telegram Bot 删除发送的照片?
- python - KivyMD:如何从 python 中添加的 TextField 获取文本
- laravel - 了解简单 Laravel 应用程序上的 JMeter 结果
- python - Discord.py 点未加载到 json 中
- c - 使用字符串文字进行数组初始化会导致两个内存存储吗?