I get this error while creating documents in mongodb.
errmsg: 'E11000 duplicate key error collection: db.events index: calendar_1_providerId_1 dup key: { : ObjectId(\'59c58ac77f8b539bacaa49f0\'), : "osv8g39so6q0cptpjhj2kk5ps4_20170602T153000Z" }',
the providerId is already there for another document with different calendarId,but I get this error due to which mongo goes down and server crashes.
eventSchema.index({ 'calendar' : 1, 'providerId': 1 }, { unique: true, sparse: true });
following is the index creation code. Could anyone help me with this? I am really stuck here and went through all possible solutions.
NOTE: the calendar field is not unique only the combination of the calendar and providerId should be unique in the document for instance same providerId can exists in two documents that has different calendar field values and also docs can have same calendar field value with different providerID values.