8

This is my mongoosejs schema. I set name unique to false, but this is what i get: MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: testdb1.images.$name_1 dup key: { : "aaa" }

imageSchema = new Schema({
    url: {
        type: String,
        unique: true,
        required: true
    },

    category: {
        type: String,
        required: true
    },

    vote: {
        type: Number,
        required: true
    },

    name: {
        type: String,
        unique: false,
        required: true
    },

    voteArray: [],
    favorite: false,
    tags: []

});

any ides how to solve this ? suggestions ?

nobody_cares_
  • 139
  • 2
  • 9

3 Answers3

9

Go to the DB(MongoDB)--> Collections --> Your_Table --> Indexes --> Right Click on the Unique Field --> Exit Index --> Uncheck the Unique field --> Save

illustration pic

Ronen Ness
  • 9,923
  • 4
  • 33
  • 50
7

Mongoose won't modify existing indexes, so you'll need to drop that index in the MongoDB shell and then let Mongoose recreate it using the definition in your schema:

> db.images.dropIndex('name_1');
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
0

MongoDB Compass

If you are using MongoDB Compass then you can choose your document and then click on Indexes and delete the index which you want to delete.

enter image description here

gprathour
  • 14,813
  • 5
  • 66
  • 90