드라이버가 포함된 MongoDB
정의
db.collection.dropIndexes()컬렉션에서 지정된 인덱스(
_id필드의 인덱스와 마지막 남은 샤드 키 인덱스 제외)를 제거합니다.이 메서드를 사용하여 다음을 수행할 수 있습니다.
collection에서
_id인덱스를 제외한 모든 항목을 제거합니다.db.collection.dropIndexes() collection에서 지정된 인덱스를 제거합니다. 인덱스를 지정하려면 다음 중 하나를 사용하여 메서드를 전달합니다.
인덱스 사양 문서(인덱스가 텍스트 인덱스가 아닌 경우, 인덱스 이름을 사용하여 제거):
db.collection.dropIndexes( { a: 1, b: 1 } )
collection에서 지정된 인덱스를 삭제합니다. 삭제할 인덱스를 여러 개 지정하려면 메서드에 인덱스 이름 배열을 전달합니다.
db.collection.dropIndexes( [ "a_1_b_1", "a_1", "a_1__id_-1" ] ) 인덱스 이름 배열에 존재하지 않는 인덱스가 포함되어 있으면 메서드는 존재하지 않는 인덱스를 무시하고 나머지 지정된 인덱스를 제거합니다.
팁
인덱스 이름을 가져오려면
db.collection.getIndexes()메서드를 사용하세요.
매개변수
The db.collection.dropIndexes() method takes the following optional parameter:
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
참고
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
행동
Starting in MongoDB 8.3, db.collection.dropIndexes() is idempotent. If you specify an index that does not exist, db.collection.dropIndexes() ignores the non-existent index and completes successfully instead of returning an IndexNotFound error. In earlier versions, db.collection.dropIndexes() returns an IndexNotFound error if the specified index does not exist.
Starting in MongoDB 6.0, db.collection.dropIndexes() raises an error if you attempt to use it to remove the last remaining shard key compatible index. Passing "*" to db.collection.dropIndexes() drops all indexes except the _id index and the last remaining shard key compatible index, if one exists.
You can use db.collection.dropIndexes() to drop existing indexes on the same collection even if there is a build in progress on another index. In earlier versions, attempting to drop a different index during an in-progress index build results in a BackgroundOperationInProgressForNamespace error.
관련 쿼리만 종료
The dropIndexes() operation only kills queries that are using the index being dropped. This may include queries considering the index as part of query planning.
리소스 잠금
db.collection.dropIndexes() obtains an exclusive lock on the specified collection for the duration of the operation. All subsequent operations on the collection must wait until db.collection.dropIndexes() releases the lock.
인덱스 이름
Starting in MongoDB 8.3, if an array of index names includes a non-existent index, db.collection.dropIndexes() ignores the non-existent index and drops the remaining specified indexes.
_id Index
_id 필드에서 기본 인덱스를 제거할 수 없습니다.
text Indexes
텍스트 인덱스를 제거하려면 인덱스 사양 문서 대신 인덱스 이름을 지정합니다.
진행 중인 인덱스 빌드 중지
If an index specified to db.collection.dropIndexes() is still building, db.collection.dropIndexes() attempts to stop the in-progress build. Stopping an index build has the same effect as dropping the built index.
For replica sets, run db.collection.dropIndexes() on the primary. The primary stops the index build and creates an associated "abortIndexBuild" oplog entry. Secondaries which replicate the "abortIndexBuild" oplog entry stop the in-progress index build and discard the build job. See Index Build Process for detailed documentation on the index build process.
currentOp을 사용하여 createIndexes 또는 db.collection.createIndexes() 작업과 관련된 인덱스 빌드를 식별합니다. 예는 활성 인덱싱 작업을 참조하세요.
Hidden Indexes
MongoDB는 쿼리 플래너에서 인덱스를 숨기거나 숨김 해제하는 기능을 제공합니다. 플래너에서 인덱스를 숨기면 실제로 인덱스를 제거하지 않고도 인덱스 제거의 잠재적 영향을 평가할 수 있습니다.
평가 후 사용자가 인덱스를 제거하기로 결정하면 숨겨진 인덱스를 제거할 수 있습니다. 즉, 인덱스를 제거하기 위해 먼저 숨기기를 해제할 필요가 없습니다.
하지만 영향이 부정적이라면 사용자는 제거된 인덱스를 다시 만들지 않고도 인덱스 숨김을 해제할 수 있습니다. 또한 인덱스는 숨겨진 상태에서도 완전히 유지되므로 숨김을 해제하면 인덱스를 즉시 사용할 수 있습니다.
숨겨진 인덱스에 대한 자세한 내용은 숨겨진 인덱스를 참조하세요.