> For the complete documentation index, see [llms.txt](https://janeto.gitbook.io/mongodb-toan-tap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://janeto.gitbook.io/mongodb-toan-tap/gioi-han-ban-ghi-trong-mongodb/phuong-thuc-limit-trong-mongodb.md).

# Phương thức limit() trong MongoDB

Để giới hạn các bản ghi trong MongoDB, bạn cần sử dụng phương thức **limit()**. Phương thức limit() nhận một tham số ở dạng kiểu số, là số Document mà bạn muốn hiển thị.

## Cú pháp <a href="#c-ph-p" id="c-ph-p"></a>

Cú pháp cơ bản của phương thức limit() là như sau:

```
>db.COLLECTION_NAME.find().limit(NUMBER)
```

## Ví dụ <a href="#v-d" id="v-d"></a>

Bạn theo dõi Collection với tên mycol có dữ liệu sau:

```
{ "_id" : ObjectId(5983548781331adf45ec5), "title":"MongoDB Overview"}

{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}

{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
```

Ví dụ sau chỉ hiển thị 2 Document trong khi truy vấn.

```
>db.mycol.find({},{"title":1,_id:0}).limit(2)

{"title":"MongoDB Overview"}

{"title":"NoSQL Overview"}

>
```

Nếu bạn không xác định tham số trong phương thức limit(), thì nó sẽ hiển thị tất cả Document từ Collection đó.
