본문 바로가기
IT

[MongoDB]E11000 duplicate key error collection

by Better Me 2022. 5. 3.
E11000 duplicate key error collection: S06P31A302.follows index: followings.username_1 dup key: { followings.username: null }
 

DB shell에 다음과 같이 입력한다.

db.컬렉션이름.getIndexes()

해당 컬렉션에서 쓰고 있는 Index들이 출력된다.

 

내가 만든 follows 컬렉션은 _id와 followings.username, followers.username을 index로 쓰고 있었다.

나는 _id만 index로 쓰고 싶었다.

 

db.컬렉션이름.dropIndex(key의 value들)

이렇게 쓰면 되고, 나의 경우 다음과 같이 수행했다.

db.follows.dropIndex({ 'followers.username': 1 },{ 'followings.username': 1 })

결과는 다음과 같다

 

댓글