What is a PyMongo Cursor? (original) (raw)

Last Updated : 25 Jul, 2025

When working with **MongoDB in Python using **PyMongo, you typically retrieve data from a collection using the find() method. But instead of getting all the matching documents at once, PyMongo returns something called a cursor.

A PyMongo cursor is a special iterable object that acts like a pointer to the result set of a MongoDB query. It allows you to fetch and process query results one document at a time rather than loading everything into memory at once.

Why do we need Cursor

Using a cursor provides several important advantages, especially when dealing with large datasets:

Cursor Customization Options

You can fine-tune the data returned by the cursor using:

Sample database is as follows: python-mongodb-sample-database6

**Example: Using Cursor in PyMongo

javascript `

from pymongo import MongoClient

Connecting to mongodb

client = MongoClient('mongodb://localhost:27017/')

with client:

db = client.GFG
lectures = db.lecture.find()

print(lectures.next())
print(lectures.next())
print(lectures.next())    

print("\nRemaining Lectures\n")
print(list(lectures))

`

**Output:

python-mongodb-cursor

**Explanation: