作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
{
"status": "Error",
"typeof": "object",
"result": {
"code": 11000,
"index": 0,
"errmsg": "E11000 duplicate key error collection: reduxpress.users index: address.email_1 dup key: { : null }",
"op": {
"mobile": "(950) 874-8901 x8729",
"_id": "571b6e353731775404ac05b9",
"points": 0,
"created": "2016-04-23T12:44:37.111Z",
"roles": "customer",
"profileImageURL": "default.png",
"email": "aditya24@gmail.com",
"password": "VF1WQZ72HEyS0a6",
"name": "Junior94",
"__v": 0
}
}
}
//用户架构 '使用严格';
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
crypto = require('crypto'),
validator = require('validator');
// generatePassword = require('generate-password'),
// owasp = require('owasp-password-strength-test');
var validateLocalStrategyProperty = function(property) {
return (property.length);
};
var validateLocalStrategyEmail = function(email) {
return (validator.isEmail(email));
};
var UserSchema = new Schema({
name: {
type: String,
trim: true,
default: '',
validate: [validateLocalStrategyProperty,
'Please fill in your first name'
]
},
password: {
type: String,
default: ''
},
email: {
type: String,
unique: true,
lowercase: true,
trim: true,
default: '',
match: /.+\@.+\..+/,
validate: [validateLocalStrategyEmail,
'Please fill a valid email address'
]
},
mobile: {
type: String,
// unique: true,
required: [true, 'User phone is required'],
trim: true
},
profileImageURL: {
type: String,
default: 'default.png'
},
roles: {
type: String,
enum: ['user', 'admin', 'shop manager', 'customer',
'operator'
],
default: ['customer'],
required: 'Please provide at least one role'
},
lastLogout: {
type: Date
},
created: {
type: Date,
default: Date.now
},
resetPasswordToken: {
type: String
},
resetPasswordExpires: {
type: Date
},
points: {
type: Number,
default: 0
}
});
module.exports = mongoose.model('User',UserSchema);
我正在尝试使用 faker 包保存生成数据的用户,但收到此错误,我在数据库中没有任何重复的电子邮件。你能告诉我错误是什么吗?我尝试了不同的方法,但没有得到任何结果
最佳答案
您的 json 文档的 email
字段的值大于 null
且 email
字段也是通知索引字段,并且您还指定了此字段unique
并且抛出异常
首先像这样删除电子邮件字段的索引
db.users.dropIndex( { "email": 1 } )
如果您需要归档电子邮件的索引,并且归档的电子邮件必须具有运动才能变为空
然后像这样创建稀疏索引
db.users.createIndex( { "email": 1 }, { sparse: true } )
关于稀疏索引
的更多知识在这里:https://docs.mongodb.org/manual/core/index-sparse/
关于javascript - "errmsg": "E11000 duplicate key error collection: reduxpress.users index: address.email_1 dup key: { : null }",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36811174/
{ "status": "Error", "typeof": "object", "result": { "code": 11000, "index": 0, "e
我是一名优秀的程序员,十分优秀!