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 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.

Image

Table 13.8 Basic methods on the Cursor object

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.206.116