문서 홈 → MongoDB 실행 및 관리 → MongoDB Atlas
배열의 객체에 대해 Atlas Search 쿼리를 실행하는 방법
이 페이지의 내용
- 개요
- 샘플 컬렉션 정보
- Atlas Search 인덱스 정보
- 쿼리 정보
- Atlas Search 플레이그라운드에서 사용해 보기
- Atlas Search 플레이그라운드에 액세스합니다.
- Data Source, Index 및 Query 창을 검토합니다.
- Run 를 클릭하거나
Command
+Enter
를 눌러 쿼리를 실행합니다. - Atlas Search 플레이그라운드에 액세스합니다.
- Data Source, Index 및 Query 창을 검토합니다.
- Run 를 클릭하거나
Command
+Enter
를 눌러 쿼리를 실행합니다. - Atlas Search 플레이그라운드에 액세스합니다.
- Data Source, Index 및 Query 창을 검토합니다.
- Run 를 클릭하거나
Command
+Enter
를 눌러 쿼리를 실행합니다. - Atlas 클러스터에서 사용해 보기
- 샘플 컬렉션 만들기 및 데이터 로드
- Atlas Search 인덱스 만들기
- 내장된 문서 필드에 대해
$search
쿼리 실행 - 내장된 문서 필드에 대해
$searchMeta
쿼리 실행
개요
이embeddedDocuments
튜토리얼에서는 배열( ) 내에 있는 문서 또는 객체의 필드에 대해 Atlas Search 쿼리를 인덱싱하고 실행하는 방법을 설명합니다. 이 페이지에는 Atlas Search 플레이그라운드 에 설정되어 있거나 Atlas cluster 에서 로드, 구성 및 실행할 수 있는 샘플 컬렉션 에 대한 샘플 인덱스 를 사용하여샘플 쿼리 를 실행하는 방법에 대한 지침이 포함되어 있습니다.
샘플 컬렉션 정보
샘플 컬렉션의 이름은 schools
이며 여기에는 세 개의 문서가 포함되어 있습니다. 샘플 컬렉션의 각 문서에는 학교의 name
및 mascot
, 학교 교사의 first
및 last
이름, 각 교사가 가르치는 classes
( subject
이름 및 grade
수준 포함)이 포함되어 있습니다. 및 학교 학생을 위한 다양한 clubs
입니다.
Atlas Search 인덱스 정보
컬렉션에 대한 인덱스 정의는 다음을 보여줍니다.
teachers
및teachers.classes
경로의 배열에 있는 문서는 embeddedDocuments 로 인덱싱되고, 문서 내부의 필드는 동적으로 인덱싱됩니다.teachers
경로의 배열에 있는 문서도 문서 유형으로 인덱싱되어 강조 표시 를 지원하며 문서 내부의 필드가 동적으로 인덱싱됩니다.필드의 문서는 동적 매핑
clubs
이 활성화된 문서 유형으로 인덱싱되고 필드의 문서clubs.sports
배열은embeddedDocuments
동적 매핑이 활성화된 유형으로 인덱싱됩니다.
쿼리 정보
샘플 쿼리는 schools
컬렉션에 내장된 문서를 검색합니다. 쿼리는 다음 파이프라인 단계를 사용합니다.
$search
collection을 검색합니다.$project
을(를) 사용하여 컬렉션에서 필드를 포함 및 제외하고 결과에score
라는 필드를 추가합니다. 강조 표시 를 활성화하는 쿼리의 경우$project
단계에서는 강조 표시 정보가 포함된highlights
이라는 새 필드도 추가합니다.
이 튜토리얼에서는 세 가지 쿼리를 보여줍니다.
Atlas Search 플레이그라운드에서 사용해 보기
Atlas Search Playground 에서는 내장된 문서 컬렉션 을 설정하고, 컬렉션의 필드에 대한 인덱스 를 사전 구성하고, 컬렉션에 대해 실행할 수 있는 쿼리 를 정의했습니다. Atlas Search 플레이그라운드에서 컬렉션, 인덱스 및 쿼리를 수정할 수도 있습니다.
Atlas 클러스터에서 사용해 보기
이 섹션에서는 내장된 문서에 대해 쿼리를 실행하는 방법을 보여 주기 위해 다음 단계를 안내합니다.
Atlas cluster에 포함된 문서가 있는
schools
이라는 샘플 collection을 만듭니다.다음 경로에 embeddedDocuments 필드를 구성하여 Atlas Search 인덱스를 설정합니다.
teachers
필드teachers.classes
필드clubs.sports
필드
embeddedDocument 및 텍스트
$search
연산자와schools
함께 복합 연산자를 사용하여 컬렉션에 내장된 문서를 검색하는 쿼리를 실행합니다.내장된 문서 필드에 대해
$searchMeta
쿼리를 실행하여 개수를 가져옵니다.
시작하기 전에 Atlas 클러스터가 필수구성 요소에 설명된 요건을 충족하는지 확인하세요. 이 튜토리얼에서는 새 컬렉션을 만들고 쿼리를 실행하는 데 필요한 문서를 로드하기 때문에 샘플 데이터를 업로드할 필요가 없습니다.
샘플 컬렉션 만들기 및 데이터 로드
먼저 Atlas cluster의 기존 데이터베이스 또는 새 데이터베이스에 schools
(이)라는 이름의 컬렉션을 만들어야 합니다. 컬렉션을 만든 후에는 샘플 데이터를 컬렉션에 업로드해야 합니다. 샘플 컬렉션의 문서에 대해 자세히 알아보려면 샘플 컬렉션 정보를 참조하세요.
이 섹션에서는 새 데이터베이스 및 컬렉션을 생성하고 컬렉션에 샘플 데이터를 로드하는 과정을 안내합니다.
다음 문서를 컬렉션에 로드합니다.
Collection이 선택되지 않은 경우
schools
collection을 선택합니다.컬렉션에 추가할 각 샘플 문서에 대해 Insert Document 를 클릭합니다.
JSON 보기({})를 클릭하여 기본 문서를 바꿉니다.
다음 샘플 문서를 한 번에 하나씩 복사하여 붙여넣고 Insert을 클릭하여 컬렉션에 문서를 한 번에 하나씩 추가합니다.
{ "_id": 0, "name": "Springfield High", "mascot": "Pumas", "teachers": [{ "first": "Jane", "last": "Smith", "classes": [{ "subject": "art of science", "grade": "12th" }, { "subject": "applied science and practical science", "grade": "9th" }, { "subject": "remedial math", "grade": "12th" }, { "subject": "science", "grade": "10th" }] }, { "first": "Bob", "last": "Green", "classes": [{ "subject": "science of art", "grade": "11th" }, { "subject": "art art art", "grade": "10th" }] }], "clubs": { "stem": [ { "club_name": "chess", "description": "provides students opportunity to play the board game of chess informally and competitively in tournaments." }, { "club_name": "kaboom chemistry", "description": "provides students opportunity to experiment with chemistry that fizzes and explodes." } ], "arts": [ { "club_name": "anime", "description": "provides students an opportunity to discuss, show, and collaborate on anime and broaden their Japanese cultural understanding." }, { "club_name": "visual arts", "description": "provides students an opportunity to train, experiment, and prepare for internships and jobs as photographers, illustrators, graphic designers, and more." } ] } } { "_id": 1, "name": "Evergreen High", "mascot": "Jaguars", "teachers": [{ "first": "Jane", "last": "Earwhacker", "classes": [{ "subject": "art", "grade": "9th" }, { "subject": "science", "grade": "12th" }] }, { "first": "John", "last": "Smith", "classes": [{ "subject": "math", "grade": "12th" }, { "subject": "art", "grade": "10th" }] }], "clubs": { "sports": [ { "club_name": "archery", "description": "provides students an opportunity to practice and hone the skill of using a bow to shoot arrows in a fun and safe environment." }, { "club_name": "ultimate frisbee", "description": "provides students an opportunity to play frisbee and learn the basics of holding the disc and complete passes." } ], "stem": [ { "club_name": "zapped", "description": "provides students an opportunity to make exciting gadgets and explore electricity." }, { "club_name": "loose in the chem lab", "description": "provides students an opportunity to put the scientific method to the test and get elbow deep in chemistry." } ] } } { "_id": 2, "name": "Lincoln High", "mascot": "Sharks", "teachers": [{ "first": "Jane", "last": "Smith", "classes": [{ "subject": "science", "grade": "9th" }, { "subject": "math", "grade": "12th" }] }, { "first": "John", "last": "Redman", "classes": [{ "subject": "art", "grade": "12th" }] }], "clubs": { "arts": [ { "club_name": "ceramics", "description": "provides students an opportunity to acquire knowledge of form, volume, and space relationships by constructing hand-built and wheel-thrown forms of clay." }, { "club_name": "digital art", "description": "provides students an opportunity to learn about design for entertainment, 3D animation, technical art, or 3D modeling." } ], "sports": [ { "club_name": "dodgeball", "description": "provides students an opportunity to play dodgeball by throwing balls to eliminate the members of the opposing team while avoiding being hit themselves." }, { "club_name": "martial arts", "description": "provides students an opportunity to learn self-defense or combat that utilize physical skill and coordination without weapons." } ] } }
Atlas Search 인덱스 만들기
이 섹션에서는 local_school_district.schools
컬렉션의 내장된 문서에 있는 필드에 대한 Atlas Search 인덱스를 만듭니다.
필요한 액세스 권한
Atlas Search 인덱스를 생성하려면 프로젝트에 대한 Project Data Access Admin
이상의 액세스 권한이 있어야 합니다.
절차
Index Name을 입력하고 Database and Collection을 설정합니다.
Index Name 필드에
embedded-documents-tutorial
를 입력합니다.참고
인덱스 이름을
default
으로 지정하면 $search 파이프라인 단계를 사용할 때index
매개 변수를 지정할 필요가 없습니다. 그렇지 않으면index
매개 변수를 사용하여 인덱스 이름을 지정해야 합니다.Database and Collection 섹션에서
local_school_district
데이터베이스를 찾고schools
컬렉션을 선택합니다.
내장된 문서를 인덱싱하는 인덱스 구성을 지정합니다.
인덱스 정의에 대해 자세히 알아보려면 Atlas Search 인덱스 정보를 참조하세요.
내장된 문서 필드에 대해 $search
쿼리 실행
내장된 문서 필드에 대해 쿼리를 실행할 수 있습니다. 이 튜토리얼에서는 쿼리에서 복합 연산자 내부의 embeddedDocument 및 텍스트 연산자를 사용합니다.
이 섹션에서는 Atlas 클러스터에 연결하고 schools
컬렉션의 필드에 대해 연산자를 사용하여 샘플 쿼리를 실행합니다.
➤ 이 페이지의 언어 선택 드롭다운 메뉴를 사용하여 이 섹션에 있는 예제의 언어를 설정합니다.
내장된 문서 필드에 대해 $searchMeta
쿼리 실행
내장된 문서 필드에 대해 $searchMeta
쿼리를 실행할 수 있습니다. 이 섹션에서는 Atlas 클러스터에 연결하고 내장된 문서 필드에서 $searchMeta
단계 및 패싯을 사용하여 샘플 쿼리를 실행합니다.