When And why use Cursor in your project?
If I have this Mock code
var mongoClient = require('mongodb').MongoClient;
mongoClient.connect('mongodb://localhost:27017/tut3',function(err,db){
if(err)throw err;
var collection = db.collection('messages');
collection.find({},{_id:true}).each(function(err,doc){
console.log("---- CLASSIC ----")
console.dir(doc);
//stuff//
});
var cursor = collection.find({},{_id:true});
cursor.each(function(err,doc){
console.log("---- CURSOR ----")
console.dir(doc);
//stuff2
});
})
The collection messages is huge for example.
Which different between //stuffand //stuff2
I know that if I do
var cursor = collection.find({},{_id:true});
I Know that when cursor return I Have all the documents (synchronous) and it has many methods, but also inside stuff, the query is complete and I have all Documents...
Where is the difference? and when use var cursor instead the "classic" find?
collection.find({},{_id:true}).each(function(err,doc){witheachinside aquery. I know that it's a cursor. but i don't understand the difference betweeneachinside a query insteadvar cursor = query