gpt4 book ai didi

javascript - "errmsg": "E11000 duplicate key error collection: reduxpress.users index: address.email_1 dup key: { : null }"

转载 作者:行者123 更新时间:2023-12-03 07:06:16 26 4
gpt4 key购买 nike

{
"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 字段的值大于 nullemail 字段也是通知索引字段,并且您还指定了此字段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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com