AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

db. 컬렉션.dropIndex() (mongosh 메서드)

db.collection.dropIndex(index)

드라이버가 포함된 MongoDB

This page documents a mongosh method. To see the equivalent method in a MongoDB driver, see the corresponding page for your programming language:

지정된 인덱스를 컬렉션에서 제거합니다.

참고

To get the index name or the index specification document for the db.collection.dropIndex() method, use the db.collection.getIndexes() method.

The db.collection.dropIndex() method takes the following parameter:

Parameter
유형
설명

index

문자열 또는 문서

필수 사항입니다. 제거할 인덱스를 지정합니다. 인덱스 이름 또는 인덱스 사양 문서로 인덱스를 지정할 수 있습니다.

텍스트 인덱스를 제거하려면 인덱스 이름을 지정하세요.

_id가 아닌 모든 인덱스를 삭제하기 위해 "*"를 지정할 수는 없습니다. 대신 db.collection.dropIndexes()를 사용하세요.

If an index specified to db.collection.dropIndex() is still building, db.collection.dropIndex() attempts to stop the in-progress build. Stopping an index build has the same effect as dropping the built index. See Stop In-Progress Index Builds for more complete documentation.

이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

참고

이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.

MongoDB 부터는 5.2 다른 인덱스 에서 빌드 진행 중이더라도 를 사용하여 동일한 컬렉션 에 있는 기존 인덱스를 삭제할 수 있습니다. 이전 버전에서는 인덱스 빌드 진행 중일 때 다른 인덱스 삭제하려고 하면 db.collection.dropIndex() BackgroundOperationInProgressForNamespace 오류가 발생했습니다.

db.collection.dropIndex() 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.dropIndex() releases the lock.

If an index specified to db.collection.dropIndex() is still building, db.collection.dropIndex() 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.dropIndex() 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() 작업과 관련된 인덱스 빌드를 식별합니다. 예는 활성 인덱싱 작업을 참조하세요.

MongoDB는 쿼리 플래너에서 인덱스를 숨기거나 숨김 해제하는 기능을 제공합니다. 플래너에서 인덱스를 숨기면 실제로 인덱스를 제거하지 않고도 인덱스 제거의 잠재적 영향을 평가할 수 있습니다.

평가 후 사용자가 인덱스를 제거하기로 결정하면 숨겨진 인덱스를 제거할 수 있습니다. 즉, 인덱스를 제거하기 위해 먼저 숨기기를 해제할 필요가 없습니다.

하지만 영향이 부정적이라면 사용자는 제거된 인덱스를 다시 만들지 않고도 인덱스 숨김을 해제할 수 있습니다. 또한 인덱스는 숨겨진 상태에서도 완전히 유지되므로 숨김을 해제하면 인덱스를 즉시 사용할 수 있습니다.

숨겨진 인덱스에 대한 자세한 내용은 숨겨진 인덱스를 참조하세요.

pets 컬렉션 에서 cat 필드 에 내림차순 인덱스 만듭니다.

db.pets.createIndex( { cat: -1 }, { name: "catIdx" } )

pets 컬렉션의 인덱스를 보려면 getIndexes() 메서드를 실행.

db.pets.getIndexes()
[
{ v: 2, key: { _id: 1 }, name: '_id_' },
{ v: 2, key: { cat: -1 }, name: 'catIdx' }
]

cat 필드 의 단일 필드 인덱스 사용자 지정 이름이 catIdx 이고 인덱스 사양 문서 { "cat" : -1 }입니다.

인덱스 catIdx를 제거하려면 인덱스 이름을 사용할 수 있습니다:

db.pets.dropIndex( "catIdx" )

또는 인덱스 사양 문서 { "cat" : -1 }을 사용할 수 있습니다.

db.pets.dropIndex( { "cat" : -1 } )

dropIndex 명령은 명령이 실행 되기 전에 컬렉션 의 인덱스 수를 반환하고 명령이 성공적인 했는지 여부를 나타냅니다.

{ nIndexesWas: 2, ok: 1 }

인덱스 삭제되었는지 확인하려면 getIndexes() 메서드를 다시 실행 .

db.pets.getIndexes()
[ { v: 2, key: { _id: 1 }, name: '_id_' } ]
이 페이지 평가하기

이 페이지의 내용