Docs Menu
Docs Home
/ /

객체 배열 쿼리, 필터링 및 조회

returnScope 옵션을 사용하여 쿼리 의 컨텍스트를 설정하다 하고 객체 배열을 개별 문서로 반환할 수 있습니다.

returnScope를 사용하여 중첩된 객체를 개별 문서로 조회 하려면 다음을 수행해야 합니다.

  • 객체 배열을 embeddedDocuments 유형으로 인덱싱합니다.

  • 조회 하려는 중첩 필드에 대해 storedSource를 정의합니다.MongoDB Search는 에 정의된 필드만 반환합니다. storedSource

  • 쿼리 에서 returnStoredSource 옵션을 로 설정합니다.true

returnScope 쿼리에 다음 구문이 있습니다.

{
$search: {
"<operator>": {
<operator-specification>,
},
"returnScope": {
"path": "<embedded-documents-field-to-retrieve>"
},
"returnStoredSource": true
}
}
{
$searchMeta: {
"returnScope": {
"path": "<embedded-documents-field-to-retrieve>"
},
"returnStoredSource": true
},
"facet": {
"<operator>": {
<operator-specification>,
},
"facets": {
<facet-definition>
}
}
}

쿼리 구문에 대해 자세히 알아보려면 $search 를 참조하세요.

returnScope 옵션은 쿼리 에 대한 검색 컨텍스트를 설정합니다. 쿼리 에 returnScope 을 지정하면 MongoDB Search는 각 내장된 문서 개별 문서 인 것처럼 점수를 매기고, 정렬하고, 계산합니다.

연산자 사양에서 쿼리 하려는 필드 의 전체 경로를 지정해야 합니다.

returnScope 옵션을 사용하는 경우 MongoDB Search는 embeddedDocument 내에서 storedSource 로 구성한 필드만 반환합니다. embeddedDocument 경로 외부의 필드(예: 루트 수준의 필드)와 storedSource 로 구성되지 않은 필드는 반환되지 않습니다.

다음 예는 쿼리에서 returnScope 옵션을 사용하는 방법을 보여줍니다. 이 예제에서는 sample_training.companies 샘플 데이터 세트를 사용합니다. 클러스터 에 데이터를 로드하고 컬렉션 의 필드에 샘플 인덱스 생성하는 경우 샘플 데이터에 대해 다음 쿼리를 시도할 수 있습니다.

1{
2 "mappings": {
3 "dynamic": false,
4 "fields": {
5 "funding_rounds": {
6 "type": "embeddedDocuments",
7 "dynamic": true,
8 "fields": {
9 "investments": {
10 "type": "embeddedDocuments",
11 "dynamic": true
12 }
13 },
14 "storedSource": {
15 "include": [
16 "round_code",
17 "raised_currency_code",
18 "raised_amount",
19 "investments.person",
20 "investments.financial_org"
21 ]
22 },
23 }
24 }
25 }
26}

위의 인덱스 정의는 MongoDB Search를 다음과 같이 구성합니다.

  • funding_roundsfunding_rounds.investments 필드를 embeddedDocuments 유형으로 인덱싱합니다.

  • 객체의 funding_roundsfunding_rounds.investments 배열 에 중첩된 동적으로 인덱싱할 수 있는 모든 필드를 인덱싱합니다.

  • 다음 필드를 mongot에 저장합니다.

    • funding_rounds.round_code

    • funding_rounds.raised_currency_code

    • funding_rounds.raised_amount

    • funding_rounds.investments.person

    • funding_rounds.investments.financial_org

연산자를 embeddedDocument 사용하여 funding_roundsfunding_rounds.investments 필드 모두에 대해 요소별 쿼리를 수행할 수 있습니다. 다음 섹션에서는 returnScope 옵션을 사용하여 embeddedDocuments 필드를 개별 문서로 조회 몇 가지 샘플 쿼리를 보여줍니다.

sample_training.companies 컬렉션의 샘플 문서 구조
{
...,
"funding_rounds": [
{
"id": <integer>,
"round_code": "<string>",
"source_url": "<string>",
"source_description": "<string>",
"raised_amount": <integer>,
"raised_currency_code": "<string>",
"funded_year": <integer>,
"funded_month": "<string>",
"funded_day": "<string>",
"investments": [
{
"company": "<string>",
"financial_org": {
"name": "<string>",
"permalink": "<string>"
},
"person": {
"first_name": "<string>",
"last_name": "<string>",
"permalink": "<string>"
}
},
...
]
},
...
],
...
}

다음 섹션에서는 returnScope 옵션을 사용하여 mongot에 저장된 embeddedDocuments 유형 필드의 필드를 조회 샘플 쿼리를 보여 줍니다.

돌아가기

searchSequenceToken

이 페이지의 내용