Please cursor topic

can anyone please explain cursor topic in the simple way because i have not understand whatb is been told

Hi @Brijnandan_44403,

By definition, A cursor is a pointer to the result set of a query. Clients can iterate through a cursor to retrieve results.

Let’s understand it this way.

What happens when you make a find query against any database in MongoDB ?


Based on the filter condition, some documents matches. The number of matched documents can range from 0 to the maximum number of documents in the collection. The number of matched documents could get really big such as millions and billions. If we transfer all the data in one go then it will be expensive and there will be performance overhead as well.

So, what happens is that instead of returning the entire result set, a cursor is returned which is just a reference point to that of the larger set of data.

And then you can iterate over the result set using the cursor. In MongoDB, by default the cursor is automatically iterated up to 20 times to print up to the first 20 documents in the results.

For more information on how to iterate over a cursor please refer our documentation.

Hope it helps.

If you have any other issue, please feel free to get back to us.

Happy Learning :slight_smile:

Shubham Ranjan
Curriculum Support Engineer