Duplicate key key error collection - I know what it is but I don't have duplicate keys

I’m getting the Duplicate key error collection message. As far as I know this issue is because there is a duplicate key in the collection. However, I do not have a duplicate key, nor do I have anything (database, collection, or key) in my data that says (classroom.class_code: null). Not sure how to fix this. It happens when I try to upload data to the server. I’m tried from the website and from Atlas (from a CVS file as well as a single item).

remove index classroom.class_code to resolve this

It looks like you might have some documents in the collection that have a null value for classroom.class_code. In this case it would be a duplicate key as the index value would also be null.

As MAY_CHEAPER mentioned, removing the index would get rid of this error. But I’m assuming you have the index there for a reason. If you need to keep the index then look into making it a partial index - https://www.mongodb.com/docs/manual/core/index-partial/

With a partial index you could write a filter to only create indexes where classroom.class_code is not null. But bear in mind, these records will not be indexed.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.