

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

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

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

Amazon DocumentDB의 `$floor` 연산자는 지정된 숫자보다 작거나 같은 가장 큰 정수를 반환합니다. 이 연산자는 숫자 값을 내림하는 데 유용합니다.

**파라미터**
+ `expression`: 반올림할 숫자 표현식입니다.

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

다음 예제에서는 `$floor` 연산자를 사용하여 십진수 값을 가장 가까운 정수로 반올림하는 방법을 보여줍니다.

**샘플 문서 생성**

```
db.numbers.insertOne({ value: 3.14 });
```

**쿼리 예제**

```
db.numbers.aggregate([
  { $project: { _id: 0, floored: { $floor: "$value" } } }
]);
```

**출력**

```
{ "floored" : 3 }
```

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

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

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

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

async function example() {
  const uri = 'mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false';
  const client = new MongoClient(uri);

  try {
    await client.connect();

    const db = client.db('test');
    const collection = db.collection('numbers');

    const result = await collection.aggregate([
      { $project: { _id: 0, floored: { $floor: "$value" } } }
    ]).toArray();

    console.log(result);

  } catch (error) {
    console.error('Error:', error);
  } finally {
    await client.close();
  }
}

example();
```

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

```
from pymongo import MongoClient
from pprint import pprint

def example():
    client = None
    try:
        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.numbers

        result = list(collection.aggregate([
            { '$project': { '_id': 0, 'floored': { '$floor': '$value' }}}
        ]))

        pprint(result)

    except Exception as e:
        print(f"An error occurred: {e}")

    finally:
        if client:
            client.close()

example()
```

------