Daga Arihant Daga Arihant - 25 days ago 7
Node.js Question

Unable to update mongoose Schema's validations

I am quiet new to mongoose, So i created a user model like this

var UserSchema = new mongoose.Schema({
name: {
type: String,
lowercase:true,
unique:true
},
phone: {
type:String,
unique:true,
sparse:true,
required:true
}});
mongoose.model('User',UserSchema);


I created this model, but later on i thought that name field should not be unique so i updated my model by removing unique attribute from name field.
but is mongoose keeping some cache or something because even after updating the code in my model file when i do a user register request i am getting this error that duplicate key for name field and it is not accepting same names for 2 documents.

this is the error i am recieving :


{ [MongoError: E11000 duplicate key error collection: kiotapp.users
index: name_1 dup key: { : "arihant daga 5" }] name: 'MongoError',

message: 'E11000 duplicate key error collection: kiotapp.users index:
name_1 dup key: { : "arihant daga 5" }',

Sam Sam
Answer
db.collection.dropIndex()

refer : https://docs.mongodb.com/v3.0/tutorial/remove-indexes/