MongoError: E11000 duplicate key error collection

created at 07-06-2021 views: 33

The batch import of mongoose is abnormal

MongoError: E11000 duplicate key error collection: linjia.users index: email_1 dup key: { : null }

Either loop or insertMany will report this error

It means that email_1 is duplicate and null, but this key is not defined in the schema.
Finally, in the visualization tool MongoDB compass community, I found that there are two keys in articles, including the email_1key. After deleting it, adding data is normal.

For those viewed through navcat, directly delete the currently created collection and regenerate it.

created at:07-06-2021
edited at: 07-06-2021: