สมัครเรียนโทร. 085-350-7540 , 084-88-00-255 , ntprintf@gmail.com

Tutorial Python MongoDB

LM41PYTHON MONGODB LM42PYHON MONGODB CREATE DATABASE LM42PYTHON MONGODB CREATE DATABASE LM43PYTHON MONGODB CREATE COLLECTION LM44PYTHON MONGODB INSERT DOCUMENT LM45PYTHON MONGODB FIND LM46PYTHON MONGODB QUERY LM47PYTHON MONGODB SORT LM48PYTHON MONGODB DELETE DOCUMENT LM49PYTHON MONGODB DROP COLLECTION LM50PYTHON MONGODB DPDATE LM51PYTHON MONGODB LIMIT

Python MongoDB Limit

เรียนเขียนโปรแกรมง่ายๆกับ Expert Programming Tutor ในบท Python MongoDB Limit
วันนี้เราจะมาเรียนรู้เกี่ยวกับการจำกัดผลลัพธ์ จะเป็นอย่างไรมาเรียนรู้กันเลย
จำกัดผลลัพธ์
เพื่อจำกัดผลลัพธ์ใน MongoDB เราใช้เมธอด limit()  เมธอด limit() รับพารามิเตอร์หนึ่งตัวซึ่งเป็นตัวเลขที่กำหนดจำนวนเอกสารที่จะส่งคืน พิจารณาว่าคุณมีคอลเลกชัน "customer"
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'}

ตัวอย่าง
จำกัด ผลลัพธ์ให้ส่งคืนเอกสาร 5 ฉบับเท่านั้น

import pymongo
myclient = 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)

ผลลัพธ์

C:\Users\My Name>python demo_mongodb_limit.py
{'_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'}

แปลจาก  https://www.w3schools.com/python/python_mongodb_limit.asp



บทความนี้อาจจะมีที่ผิด กรุณาตรวจสอบก่อนใช้

หากมีข้อผิดพลาด/ต้องการพูดคุยเพิ่มเติมเกี่ยวกับบทความนี้ กรุณาแจ้งที่ http://m.me/Expert.Programming.Tutor

ไม่อยากอ่าน Tutorial อยากมาเรียนเลยทำอย่างไร?

สมัครเรียน ONLINE ได้ทันทีที่ https://elearn.expert-programming-tutor.com

หรือติดต่อ

085-350-7540 (DTAC)
084-88-00-255 (AIS)
026-111-618
หรือทาง EMAIL: NTPRINTF@GMAIL.COM

แผนที่ ที่ตั้งของอาคารของเรา

C Article


C++ Article


Java Article


C#.NET Article


VB.NET Article


Python Article


Golang Article


JavaScript Article


Perl Article


Lua Article


Rust Article


Article


Python


Python Numpy


Python Machine Learning



แผนผังการเรียนเขียนโปรแกรม

Link อื่นๆ

Allow sites to save and read cookie data.
Cookies are small pieces of data created by sites you visit. They make your online experience easier by saving browsing information. We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies.

Copyright (c) 2013 expert-programming-tutor.com. All rights reserved. | 085-350-7540 | 084-88-00-255 | ntprintf@gmail.com

ติดต่อเราได้ที่

085-350-7540 (DTAC)
084-88-00-255 (AIS)
026-111-618
หรือทาง EMAIL: NTPRINTF@GMAIL.COM
แผนที่ ที่ตั้งของอาคารของเรา