MongoDB Cursor Example

In this example, we are working with:

Database: gfg

Collection: student

Documents: Three documents contain the details of the students

Here, we use the following query to display all the documents present in the student collection

db.student.find().pretty()

This find() method returns a cursor containing all documents present in the student collection.

MongoDB Cursor

The MongoDB cursor is a pointer that references the documents of the collection returned by the find() method.

The cursor is used to access the documents. By default, the cursor iterates automatically, but can also be iterated manually by the user.

Similar Reads

MongoDB Cursor Example

In this example, we are working with:...

How to Manually Iterate a Cursor in MongoDB

There are different ways to manually iterate a cursor in MongoDB. Users can manually iterate a cursor in MongoDB by:...

MongoDB Cursor Methods

Some of the commonly used cursor methods are:...

Additional Cursor Methods in MongoDB

Cursor Methods modify the way that the underlying query is executed....

Conclusion

Cursors in MongoDB reference the documents of a collection returned by the find() method. A cursor is used to iterate over documents when the query result is returned....

Contact Us