

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# \$1in
<a name="in"></a>

Amazon DocumentDB의 `$in` 연산자는 필드 값이 배열에 지정된 값과 동일한 문서를 찾을 수 있는 논리적 쿼리 연산자입니다.

**파라미터**
+ `field`: 제공된 배열과 비교하여 확인할 필드입니다.
+ `[value1, value2, ...]`: 지정된 필드와 일치시킬 값의 배열입니다.

 

**필드 이름의 달러(`$`)**

중첩된 객체에서의 `$` 접두사 필드 쿼리`$in`와 관련된 [필드 이름의 달러(\$1) 및 점(.)](functional-differences.md#functional-differences-dollardot) 제한 사항은 섹션을 참조하세요.

## 예제(MongoDB 쉘)
<a name="in-examples"></a>

다음 예제에서는 `$in` 연산자를 사용하여 `color` 필드가 제공된 배열의 값 중 하나인 문서를 찾는 방법을 보여줍니다.

**샘플 문서 생성**

```
db.colors.insertMany([
  { "_id": 1, "color": "red" },
  { "_id": 2, "color": "green" },
  { "_id": 3, "color": "blue" },
  { "_id": 4, "color": "yellow" },
  { "_id": 5, "color": "purple" }
])
```

**쿼리 예제**

```
db.colors.find({ "color": { "$in": ["red", "blue", "purple"] } })
```

**출력**

```
{ "_id": 1, "color": "red" },
{ "_id": 3, "color": "blue" },
{ "_id": 5, "color": "purple" }
```

## 코드 예제
<a name="in-code"></a>

`$in` 명령을 사용하기 위한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

------
#### [ Node.js ]

```
const { MongoClient } = require('mongodb');

async function findByIn() {
  const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false');
  const db = client.db('test');
  const collection = db.collection('colors');

  const result = await collection.find({ "color": { "$in": ["red", "blue", "purple"] } }).toArray();
  console.log(result);

  await client.close();
}

findByIn();
```

------
#### [ Python ]

```
from pymongo import MongoClient

def find_by_in():
    client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
    db = client.test
    collection = db.colors

    result = list(collection.find({ "color": { "$in": ["red", "blue", "purple"] } }))
    print(result)

    client.close()

find_by_in()
```

------