Description
On this page, which google shows when users try to understand how to iterate through results of a cursor in javascript using the Mongo shell, there is no example that iterates document by document, w/o bringing the result into memory.
In particular, this example needs a loop:
var myCursor = db.inventory.find( { type: 'food' } );
|
var myDocument = myCursor.hasNext() ? myCursor.next() : null;
|
|
|
if (myDocument) {
|
var myItem = myDocument.item;
|
print(tojson(myItem));
|
}
|