标签:aio client tps tom gre john span href tar
要限制 MongoDB 中的结果,我们使用 limit() 方法。
limit() 方法接受一个参数,定义的数字表示返回的文档数。
假设你有一个 "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)
# 打印结果:
for x in myresult:
print(x)
以上就是 Python MongoDB Limit 的详细内容,更多请关注w3school其它相关文章!
重庆代孕【徽信13022337922】、成都代孕【徽信13022337922】、长沙代孕【徽信13022337922】、
武汉代孕【徽信13022337922】、贵阳代孕【徽信13022337922】、昆明代孕【徽信13022337922】
标签:aio client tps tom gre john span href tar
原文地址:https://www.cnblogs.com/yuya670/p/12858399.html