Meteor-Community-Packages / meteor-schema-index

Control some MongoDB indexing with schema options

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Got duplicate key error dup key: { : undefined }

sonlexqt opened this issue · comments

I have an array field called udids in Meteor.users schema, which should contains unique elements. This is how I defined the index using SimpleSchema and Collection2:

new SimpleSchema({
  ...
  udids: {
    type: Array,
    index: true,
    unique: true,
    optional: true,
    sparse: true,
  },
  'udids.$': {
    type: String,
  },
  ...
})

However, when I start the app, I got this error: E11000 duplicate key error collection: meteor.users index: c2_udids dup key: { : undefined }. I tried searching for the documents with udids = undefined in the database: db.users.find({ udids: { $type: 6 } }) but it returns nothing.

Just a wild guess, try clearing indexes and then set them back. (index, unique, sparce, etc set to false).

from documentation.
IMPORTANT: If you need to change anything about an index, you must first start the app with index: false to drop the old index, and then restart with the correct index properties.

Agree with @max-litv. Might be resolved when #21 is finished and released.