var UserSchema = new Schema({
"username": {type: String, unique: true },
"password": String,
})
so I changed the property name to username, and ever since then things have been going to SHIT.
No matter what I do, I keep getting the error
E11000 duplicate key error index: test.users.$name_1 dup key: { : null }
Even when I try dropping the database, changing the name of the database im connecting to, and remove unique: true from the schema, I STILL GET THIS ERROR.
I literally can't get this error removed no matter what I do, why is it still throwing this error even after I delete every database AND remove the unique property...
Here's the save function -
router.post('/register', function(req, res){
var user = new User();
user.username = req.body.username;
//hash the password
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(req.body.password, salt, function(err, hash) {
user.password = hash;
user.save(function(err){
if(err){
console.log(err.message);
if(err.message === "E11000 duplicate key error index: test.users.$name_1 dup key: { : \"" + user.username + "\" }"){ //this was working fine before i changed user.name to user.username
res.json({
error: "name already taken"
});
}else{
res.json({
error: "There was an error processing your registration."
});
}
return(err);
}
res.json({user: user});
})
});
});
});