express - UnhandledPromiseRejectionWarning: MongoError: E11000 duplicate key error collection: db.footballers index: data_1 dup key: { data: null }
问题描述
我以前从未遇到过这个问题。我一直在轻松创建实例。但是有了这个项目,它给我带来了关于索引或其他东西的错误。我什至不知道那是什么。先感谢您。
这是我的架构
const mongoose = require("mongoose");
const footballersSchema = new mongoose.Schema({
name: {
type: String,
required: true,
unique: true
}
})
module.exports = mongoose.model('footballers', footballersSchema);
并且只是触发创建新实例的简单控制器
exports.checkUserForReg = async function(req, res, next){
await footballersModel.create(req.body);
res.(201).json({status: "Ok"})
}
但它给了我错误UnhandledPromiseRejectionWarning: MongoError: E11000 duplicate key error collection: db.footballers index: data_1 dup key: { data: null }
是的,每个实例都应该有唯一的名称字段,但即使我尝试不同,它也会给我这个错误。我看到错误提示,但我的架构中index: data_1 dup key: { data: null }
根本没有密钥!index
那是什么 ?谢谢!
解决方案
推荐阅读
- spring-mvc - 在启动 tomcat 服务器后的控制台中,我收到错误消息。当我的 spring mvc projetc 部署在 tomcat7 上时
- python - 如何在 Python 中从 netCDF 中提取经度和纬度范围内的数据?
- javascript - Javascript - 如何使用数组作为引用来引用对象嵌套值
- vba - 在鼠标点击时传递一个新值
- python - 使用 Spotipy 中 sp.albums 的 .json 输出从同一艺术家的多个专辑中获取曲目 ID
- python - 我可以在python主屏幕的弹出窗口中打开外部文件的gui屏幕吗?
- javascript - 我如何向第三方解释最后一行
- javascript - 灰盒渲染 react-google-maps 的 StandaloneSearchBox
- python - 在给定不同列的情况下修改 pandas 数据框列中的值具有所需的值
- sql - 将 SQL 结果输出到 JSON(基于特定列的逐行)[Microsoft SQL Server]