限制结果
限制结果详细操作教程
以下实例为学习限制结果,具体代码如下:
# Filename : example.py
# Author by : www.lidihuo.com
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["lidihuodb"]
mycol = mydb["users"]
myresult = mycol.find().limit(5)
#print the result:
for x in myresult:
print(x)
执行以上代码输出结果为:
# Filename : example.py
# Author by : www.lidihuo.com
{'_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'}