

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

# $isNumber
<a name="isNumber"></a>

버전 8.0.1에서 새로 추가되었습니다.

Amazon DocumentDB의 `$isNumber` 연산자는 지정된 표현식이 숫자 유형(정수, 소수, 이중, 길이)으로 확인되는지 여부를 나타내는 부울을 반환합니다. 배열의 모든 요소가 숫자인 경우에도 배열은 숫자로 간주되지 않습니다. 예를 들어 값에 `$isNumber` 적용된는를 `[1, 2, 3]` 반환합니다`false`.

**파라미터**
+ `expression`: 숫자 유형으로 확인되는지 여부를 확인하는 표현식입니다.

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

다음 예제에서는 `$isNumber` 연산자를 사용하여 필드 값이 숫자인지 확인하는 방법을 보여줍니다.

**샘플 문서 생성**

```
db.data.insertMany([
  {_id: 1, value: 42},
  {_id: 2, value: "hello"},
  {_id: 3, value: 3.14},
  {_id: 4, value: null}
]);
```

**쿼리 예제**

```
db.data.aggregate([
  { $project: { isNum: { $isNumber: "$value" } } }
]);
```

**출력**

```
[
  {_id: 1, isNum: true},
  {_id: 2, isNum: false},
  {_id: 3, isNum: true},
  {_id: 4, isNum: false}
]
```

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

`$isNumber` 연산자 사용에 대한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

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

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

async function example() {
  const client = new MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false');
  try {
    await client.connect();
    const db = client.db('test');
    const collection = db.collection('data');
    const result = await collection.aggregate([
      { $project: { isNum: { $isNumber: "$value" } } }
    ]).toArray();
    console.log(result);
  } finally {
    await client.close();
  }
}
example();
```

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

```
from pymongo import MongoClient

def example():
    client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
    try:
        db = client['test']
        collection = db['data']
        result = list(collection.aggregate([
            {'$project': {'isNum': {'$isNumber': '$value'}}}
        ]))
        print(result)
    finally:
        client.close()

example()
```

------