When you perform certain operations on MongoDB using the MongoDB Node.js driver, the result comes back as a Cursor
object. The Cursor
object acts as a pointer that can be iterated on to access a set of objects in the database. For example, when you use find()
, the actual documents are not returned in the callback function; rather, a Cursor
object is returned. You can then use the Cursor
object to read the items in the results.
Because the Cursor
object can be iterated on, an index to the current location is kept internally. That way, you can read items one at a time. Keep in mind that some operations only affect the current item in the Cursor
object and increment the index. Other operations affect all items from the current index forward.
To give you an overall view of the Cursor
object, Table 13.8 lists the basic methods you can call on the Cursor
object. These methods allow you to add and modify documents in the collection, find documents, and delete the collection.