Understanding the Cursor Object
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access