정의
dropIndexes버전 6.0에서 변경되었습니다.
The
dropIndexescommand drops one or more indexes (except the index on the_idfield and the last remaining shard key index, if one exists) from the specified collection.팁
In
mongosh, this command can also be run through thedb.collection.dropIndex()anddb.collection.dropIndexes()helper methods..Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
명령은 다음과 같은 구문을 가집니다:
db.runCommand( { dropIndexes: <string>, index: <string|document|arrayofstrings>, writeConcern: <document>, comment: <any> } )
명령 필드
이 명령은 다음 필드를 사용합니다.
필드 | 유형 | 설명 |
|---|---|---|
dropIndexes | 문자열 | 인덱스를 제거할 컬렉션의 이름입니다. |
index | 문자열 또는 문자열의 문서 또는 배열 | |
쓰기 고려 | 문서 | |
| any | 선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.
댓글은 유효한 모든 BSON types (문자열, 정수, 객체, 배열 등)이 될 수 있습니다. |
행동
MongoDB 부터 6.0 를dropIndexes 사용하여 마지막 남은 샤드 키 호환 인덱스 제거 하려고 하면 "*" 오류가 dropIndexes 발생합니다. 를 로 전달하면 _id 인덱스 와 마지막 남은 샤드 키 호환 인덱스(있는 경우)를 제외한 모든 인덱스가 삭제됩니다.
Starting in MongoDB 5.2, you can use 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.
리소스 잠금
dropIndexes obtains an exclusive lock on the specified collection for the duration of the operation. All subsequent operations on the collection must wait until dropIndexes releases the lock.
인덱스 이름
존재하지 않는 인덱스가 포함된 인덱스 이름 배열이 메서드에 전달되면 메서드는 지정된 인덱스를 제거하지 않고 오류를 발생시킵니다.
_id Index
_id 필드에서 기본 인덱스를 제거할 수 없습니다.
text Indexes
텍스트 인덱스를 제거하려면 인덱스 사양 문서 대신 인덱스 이름을 지정합니다.
진행 중인 인덱스 빌드 중지
If an index specified to dropIndexes is still building, 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 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는 쿼리 플래너에서 인덱스를 숨기거나 숨김 해제하는 기능을 제공합니다. 플래너에서 인덱스를 숨기면 실제로 인덱스를 제거하지 않고도 인덱스 제거의 잠재적 영향을 평가할 수 있습니다.
평가 후 사용자가 인덱스를 제거하기로 결정하면 숨겨진 인덱스를 제거할 수 있습니다. 즉, 인덱스를 제거하기 위해 먼저 숨기기를 해제할 필요가 없습니다.
하지만 영향이 부정적이라면 사용자는 제거된 인덱스를 다시 만들지 않고도 인덱스 숨김을 해제할 수 있습니다. 또한 인덱스는 숨겨진 상태에서도 완전히 유지되므로 숨김을 해제하면 인덱스를 즉시 사용할 수 있습니다.
숨겨진 인덱스에 대한 자세한 내용은 숨겨진 인덱스를 참조하세요.
예시
_id이 아닌 모든 인덱스를 삭제하려면index에"*"를 지정합니다.db.runCommand( { dropIndexes: "collection", index: "*" } ) 단일 인덱스를 제거하려면 제거하려는 인덱스의 이름을 지정하여 명령을 실행합니다. 예를 들어,
age_1이라는 인덱스를 제거하려면 다음 명령을 사용합니다.db.runCommand( { dropIndexes: "collection", index: "age_1" }) mongoshprovides the helper methodsdb.collection.dropIndex()anddb.collection.dropIndexes():db.collection.dropIndex("age_1"); 여러 인덱스를 제거하려면 인덱스 이름의 배열을 지정하여 명령을 실행합니다.
db.runCommand( { dropIndexes: "collection", index: [ "age_1", "age_1_status_1" ] } )