M ONGODB LIMIT Limit the Result To limit the result in MongoDB, we use the limit() method. The limit() method takes one parameter, a number defining how many documents to return. Limit the result to only return 5 documents: 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) {'_id': ObjectId('6325d5001d9e9d4c027643b8'), 'name': 'Kartik'} {'_id': ObjectId('6325e1ef7e4337dbd6d8b9a1'), 'name': 'Kartik'} {'_id': ObjectId('6325e20d0bea1e2841fcdd06'), 'name': 'Kartik'} {'_id': ObjectId('6325e2381039de66af625c07'), 'name': 'Kartik'} {'_id': ObjectId('6325e26da4ef8259d33e1a33'), 'name': 'Kartik'}
FOR BEGINNER PROGRAMMER & COMPUTER SCIENCE STUDENTS