Reputation: 277
This error is really confusing. I can create record once but second time no matter what, error would appear:
E11000 duplicate key error index: test_db.students.$code_1 dup key: { : null }
This is my schema:
var Schema = {
"stuCode" : String,
"firstName" : Boolean,
"lastName" : Boolean,
"email" : String
};
Before I had stuCode
as code
and _code
and it was required it's unique. That could maybe cause a problem.
I've tried to delete all the data from that collection, remove collection in mongoose.connection.on('open', function(){ });
but the problem is still there. I can only save first record and second one is impossible to save.
What would be the solution for this problem?
Upvotes: 1
Views: 217
Reputation: 5557
Before I had stuCode as code and _codeand it was required it's unique. That could maybe cause a problem.
Yes that old index on code
is probably still there, can't you drop it ?
Upvotes: 1