Cookies help us deliver our services. By using our services, you agree to our use of cookies. More information


From NoSQLZoo
Jump to: navigation, search

MongoDB's find() method returns a cursor object which can be iterated using while, hasNext() and next, or by using forEach().

Iterating countries in South America stored in the 'world' collection.

let cursor ={continent: "South America"});
while (cursor.hasNext()) {
let cursor ={continent: "South America"});

Cursors can also be converted to other JavaScript collection types, such as arrays.
In the following example an array is used to find the nth record in a result as an alternative to .find().skip(n).limit(1)

Find the 3rd result of the previous example.{continent:"South America"}).toArray()[3];