---
title: Python MongoDB Limit
description: "## Limit the Result – Хязгаарлалт тогтоох To limit the result in MongoDB, we use the `limit()` method. MongoDB-д үр дүнг хязгаарлахын тулд `limit()` аргыг ашигладаг. The `limit()` method takes one parameter, a number defining how many documents to return. `limit()` арга нь нэг…"
url: "https://apprentice.mn/docs/python-mongodb-limit/"
updated: "2024-08-05"
category: Python
---

# Python MongoDB Limit

## Limit the Result – Хязгаарлалт тогтоох

To limit the result in MongoDB, we use the `limit()` method.

MongoDB-д үр дүнг хязгаарлахын тулд `limit()` аргыг ашигладаг.

The `limit()` method takes one parameter, a number defining how many documents to return.

`limit()` арга нь нэг параметр авдаг бөгөөд энэ нь хэдэн баримт бичгийг буцаахыг тодорхойлдог тоо юм.

Consider you have a “customers” collection:

Тухайлбал, танд “customers” цуглуулга байна гэж үзье:

##### Customers

`{'_id': 1, 'name': 'John', 'address': 'Highway37'}{'_id': 2, 'name': 'Peter', 'address': 'Lowstreet 27'}{'_id': 3, 'name': 'Amy', 'address': 'Apple st 652'}{'_id': 4, 'name': 'Hannah', 'address': 'Mountain 21'}{'_id': 5, 'name': 'Michael', 'address': 'Valley 345'}{'_id': 6, 'name': 'Sandy', 'address': 'Ocean blvd 2'}{'_id': 7, 'name': 'Betty', 'address': 'Green Grass 1'}{'_id': 8, 'name': 'Richard', 'address': 'Sky st 331'}{'_id': 9, 'name': 'Susan', 'address': 'One way 98'}{'_id': 10, 'name': 'Vicky', 'address': 'Yellow Garden 2'}{'_id': 11, 'name': 'Ben', 'address': 'Park Lane 38'}{'_id': 12, 'name': 'William', 'address': 'Central st 954'}{'_id': 13, 'name': 'Chuck', 'address': 'Main Road 989'}{'_id': 14, 'name': 'Viola', 'address': 'Sideway 1633'}`

#### Example – Жишээ

Limit the result to only return 5 documents:

Зөвхөн 5 баримт бичгийг үр дүнд буцаах:

`import pymongomyclient = pymongo.MongoClient("mongodb://localhost:27017/")mydb = myclient["mydatabase"]mycol = mydb["customers"]myresult = mycol.find().limit(5)#print the result:for x in myresult:  print(x)`

        [https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-mongodb-limit%2F&linkname=Python%20MongoDB%C2%A0Limit](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-mongodb-limit%2F&linkname=Python%20MongoDB%C2%A0Limit)[https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-mongodb-limit%2F&linkname=Python%20MongoDB%C2%A0Limit](https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-mongodb-limit%2F&linkname=Python%20MongoDB%C2%A0Limit)[https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-mongodb-limit%2F&linkname=Python%20MongoDB%C2%A0Limit](https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fpython-mongodb-limit%2F&linkname=Python%20MongoDB%C2%A0Limit)[https://www.addtoany.com/share](https://www.addtoany.com/share)
