node.js – MongoDB error E11000 duplicate key error collection due to empty array containing document with email null
Table of Contents
This is the code I am writing:
const createOrgPerso= new Person({
org: newOrganisation._doc.id,
// data: [],
});
But the empty array is still getting created. And then this code is run again, it gives E 11000 duplicate key error collection: managerhq.studentdatas index: data.email_l dup key: { data.email: null } error
Problem description :
I think this is because I have set required: true for some fields.
What I want is:
Just create a document with the org field only. I will fill the data array with documents later.
My goal is: same email(also few other fields) cannot be repeated in the data array
This is the mongoose schema
The indexes in that collection

If any more details is required, please tell in comments.
Read more here: Source link


