1

im getting 'E11000' error while i'm trying to create second record (for TipSchema) in my database. My models looks like this:

var TipSchema = new mg.Schema({
    created: String,
    title: String,
    toWin: String,
    stake: String,
    imagecover: String,
    tipcontext: String,
    isFree: String,
    result: String
});

var UserSchema = new mg.Schema({
    username: {type: String, required: true, index: true, unique: true},
    password: String,
    mail: String
});

Error: "E11000 duplicate key error index: x.y.$username_1 dup key: { : null }' }"

my indexes looks like this:

INDEXED FIELD(S) UNIQUE SPARSE TTL SIZE { "_id": 1 } (true) (false) - 7.98 KB { "username": 1 } true (false) - 7.98 KB

What should i do to get this going? Few days ago i didn't have this problem, is that caused by "DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead."?

I've dropped entire db, and made everything again, but didn't help.

J4GD33P 51NGH
  • 630
  • 1
  • 8
  • 24
GR34SE
  • 163
  • 1
  • 1
  • 7
  • 1
    https://stackoverflow.com/questions/24430220/e11000-duplicate-key-error-index-in-mongodb-mongoose – J4GD33P 51NGH Sep 07 '18 at 14:08
  • Should just need to add `sparse: true` to your `username` definition and then drop the index (or collection) so that it can be rebuilt properly. – JohnnyHK Sep 07 '18 at 14:40

0 Answers0