Docs Menu
Docs Home
/ /

hasAncestor 연산자

hasAncestor

hasAncestor 연산자 ancestorPath에 지정한 embeddedDocuments 유형 필드 쿼리합니다. ancestorPathreturnScope에 지정한 필드 의 상위 항목입니다. returnScope 는 조회 하려는 중첩 수준을 포함하여 중첩된 필드 지정합니다.

배열 내의 객체를 독립적인 문서로 점수를 매기고 검색할 때 이 연산자 사용하여 다음을 수행할 수 있습니다.

  • 상위 필드를 필터링합니다(상위 중첩 수준).

  • 형제 필드를 필터링합니다(동일한 중첩 수준).

hasAncestor 연산자의 구문은 다음과 같습니다.

1{
2 $search: {
3 "index": "<index name>", // optional, defaults to "default"
4 "hasAncestor": {
5 "ancestorPath": "<embeddedDocuments-type-higher-level-field>",
6 "operator": {
7 <operator-specification>
8 }
9 },
10 "returnScope": {
11 "path": "<embeddedDocuments-type-field-to-retrieve>"
12 }
13 }
14}
필드
유형
설명
필요성

ancestorPath

문자열

쿼리 에 사용된 중첩 필드 의 중간 조상인 embeddedDocuments 유형 필드 의 이름입니다. 연산자 평가하는 상위 문서 입니다.

필수 사항

operator

객체

ancestorPath에 지정된 embeddedDocuments 유형 필드 내의 중첩 필드 쿼리 데 사용하는 연산자입니다. 쿼리 경로는 중첩 수준에 관계없이 ancestorPath의 하위 경로여야 합니다. 상위 문서 필터하다 위한 검색 기준을 지정합니다.

연산자 사양 내에서는 hasAncestor 연산자 사용할 수 없습니다.

필수 사항

이 연산자 사용하려면 다음을 수행해야 합니다.

  • 앤세스터 필드를embeddedDocuments 유형으로 ancestorPath 인덱싱합니다. 쿼리 에서 이 필드 로 를 지정합니다. 필드 루트 수준에 있는 경우 hasRoot를 사용합니다.

  • 쿼리 및 조회 할 문서 의 범위를 설정하다 하려면 returnScope 를 지정합니다.

이 섹션의 예제에서는 sample_training.companies 데이터 세트를 사용합니다. 샘플 데이터 세트를 로드하고 컬렉션 에 인덱스 생성하는 경우 이 섹션에 설명된 샘플 쿼리를 시도할 수 있습니다.

이 섹션의 쿼리는 다음 인덱스 사용합니다. 이 인덱스 정의는 다음을 수행하도록 MongoDB Search를 구성합니다.

  • 컬렉션에서 동적으로 인덱싱할 수 있는 모든 필드를 자동으로 인덱싱합니다.

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

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

    • funding_rounds.investments.financial_org

    • funding_rounds.investments.person

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

다음 쿼리 equals 연산자 사용하여 2005 연도에 설립된 회사의 funding_rounds.founded_year 필드 검색하여 회사에 투자한 금융 조직 또는 개인과 같은 투자 세부 정보를 조회 .

1db.companies.aggregate([
2 {
3 "$search": {
4 "returnStoredSource": true,
5 "returnScope": { "path": "funding_rounds.investments" },
6 "hasAncestor": {
7 "ancestorPath": "funding_rounds",
8 "operator": {
9 "equals": {
10 "path": "funding_rounds.funded_year",
11 "value": 2005
12 }
13 }
14 }
15 }
16 }
17])
[
{
financial_org: {
name: 'Frazier Technology Ventures',
permalink: 'frazier-technology-ventures'
},
person: null
},
{
financial_org: { name: 'Trinity Ventures', permalink: 'trinity-ventures' },
person: null
},
{
financial_org: { name: 'Accel Partners', permalink: 'accel-partners' },
person: null
},
{
financial_org: null,
person: {
first_name: 'Mark',
last_name: 'Pincus',
permalink: 'mark-pincus'
}
},
{
financial_org: null,
person: {
first_name: 'Reid',
last_name: 'Hoffman',
permalink: 'reid-hoffman'
}
},
{
financial_org: { name: 'First Round Capital', permalink: 'first-round-capital' },
person: null
},
{
financial_org: null,
person: {
first_name: 'Ram',
last_name: 'Shriram',
permalink: 'ram-shriram'
}
},
{
financial_org: null,
person: {
first_name: 'Mitch',
last_name: 'Kapor',
permalink: 'mitch-kapor'
}
},
{
financial_org: null,
person: { first_name: 'Ron', last_name: 'Conway', permalink: 'ron-conway' }
},
{
financial_org: null,
person: {
first_name: 'Silvio',
last_name: 'Scaglia',
permalink: 'silvio-scaglia'
}
},
{
financial_org: {
name: 'Shelter Capital Partners',
permalink: 'shelter-capital-partners'
},
person: null
},
{
financial_org: { name: 'First Round Capital', permalink: 'first-round-capital' },
person: null
},
{
financial_org: {
name: 'Liberty Associated Partners',
permalink: 'liberty-associated-partners'
},
person: null
},
{
financial_org: { name: 'Rose Tech Ventures', permalink: 'rose-tech-ventures' },
person: null
},
{
financial_org: { name: 'First Round Capital', permalink: 'first-round-capital' },
person: null
},
{
financial_org: { name: 'Lead Dog Ventures', permalink: 'lead-dog-ventures' },
person: null
},
{
financial_org: { name: 'Accel Partners', permalink: 'accel-partners' },
person: null
},
{
financial_org: { name: 'Benchmark', permalink: 'benchmark-2' },
person: null
},
{
financial_org: { name: 'Sequoia Capital', permalink: 'sequoia-capital' },
person: null
},
{ financial_org: null, person: null }
]

돌아가기

geoWithin

이 페이지의 내용