javascript - 为什么此错误显示“非法参数:未定义,字符串”?
问题描述
我正在构建一个简单的 node.js 应用程序。我为用户注册构建了我的后端 api。我正在尝试使用邮递员对其进行测试,但出现此错误“非法参数:未定义,字符串”。什么可以为此负责?相关代码如下
用户模式
const mongoose = require('mongoose');
const Schema = mongoose.Schema
const UserSchema = new Schema({
userName: {
type: String,
required: true,
unique: true
},
firstName: {
type: String,
},
lastName: {
type: String,
},
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
},
dateOfRegistration: {
type: Date,
default: Date.now
},
dateOfBirth: {
type: Date,
},
userCategory: {
type: String,
default: 'workingClass'
}
})
module.exports = mongoose.model('users', UserSchema)
解决方案
问题已解决。Postman 以“文本”格式而不是“JSON”格式发送请求,因此后端无法理解数据。将我的邮递员的设置从“文本”更改为“JSON”时,一切正常。
推荐阅读
- python - 即使命令成功,为什么 subprocess.run 创建返回码 1?
- node.js - 错误:使用 DocumentClient 读取 DynamoDB put 请求的 ECONNRESET
- c# - 尝试连接 Arxivar WCF 服务时出错
- game-maker-studio-2 - 未找到 ndk-bundle (GameMaker: Studio 2)
- javascript - 使用 JavaScript 生成随机按钮
- pandas - 如果它们在另一列中部分匹配,则在新列中填充值
- cypher - 合并agensgeaph中的重复节点
- python - 如何更改 django-robots 中的主机?
- java - 带有 oauth2 和 JWT xml 配置的 Spring MVC
- python - 在浏览器中运行 Python 3 Turtle 程序