개요
Atlas Search 기능을 사용하면 MongoDB Atlas에서 호스팅되는 컬렉션에서 전체 텍스트 검색을 수행할 수 있습니다. Atlas Search 인덱스는 검색 동작과 인덱싱할 필드를 지정합니다.
컬렉션에서 다음과 같은 메서드를 호출하여 Atlas Search 인덱스를 관리할 수 있습니다.
createSearchIndex()createSearchIndexes()listSearchIndexes()updateSearchIndex()dropSearchIndex()
참고
Atlas Search 인덱스 관리 메서드는 비동기적으로 실행 , 성공적으로 실행되었는지 확인하기 전에 반환될 수 있습니다. 인덱스의 현재 상태를 확인하려면 listSearchIndexes() 메서드를 호출합니다.
다음 섹션에서는 코드 예시를 제공하여 이전의 각 메서드를 사용하는 방법을 보여줍니다.
검색 인덱스 만들기
createSearchIndex() 및 createSearchIndexes() 메서드를 사용하여 하나 이상의 Atlas Search 인덱스를 만들 수 있습니다.
다음 코드 예시에서는 단일 인덱스를 생성하는 방법을 보여줍니다.
val index = Document("mappings", Document("dynamic", true)) collection.createSearchIndex("<index name>", index)
다음 코드 예시에서는 여러 인덱스를 생성하는 방법을 보여줍니다.
val indexOne = SearchIndexModel("<first index name>", Document("mappings", Document("dynamic", true))) val indexTwo = SearchIndexModel("<second index name>", Document("mappings", Document("dynamic", true))) collection.createSearchIndexes(listOf(indexOne, indexTwo))
Atlas Search 인덱스를 정의하는 데 사용되는 구문에 대해 자세히 알아보려면 Atlas 매뉴얼의 Atlas Search 인덱스 구문 검토 가이드를 참조하세요.
검색 인덱스 나열
listSearchIndexes() 메서드를 사용하여 컬렉션의 모든 Atlas Search 인덱스를 반환할 수 있습니다.
다음 코드 예시에서는 컬렉션의 검색 인덱스 목록을 출력하는 방법을 보여줍니다.
val results = collection.listSearchIndexes() results.forEach { result -> println(result) }
검색 인덱스 업데이트
updateSearchIndex() 메서드를 사용하여 Atlas Search 인덱스를 업데이트할 수 있습니다.
다음 코드에서는 검색 업인덱스를데이트하는 방법을 보여줍니다.
val newIndex = Document("mappings", Document("dynamic", true)) collection.updateSearchIndex("<index to update>", newIndex)
검색 인덱스 삭제
dropSearchIndex() 메서드를 사용하여 Atlas Search 인덱스 삭제 수 있습니다.
다음 코드에서는 컬렉션에서 검색 인덱스를 삭제하는 방법을 보여줍니다.
collection.dropIndex("<index to delete>")
추가 정보
MongoDB Atlas Search에 대해 자세히 학습하려면 Atlas Search Indexes 문서를 참조합니다.