mongodb - snapshot option of find method not working -
my code
method 1:
... var cursor = collection.find({}, {snapshot: true}); //i made sure insert new document collection before below timer fires settimeout(function(){ cursor.each(function(err, docu){ console.log("cursor items", docu); }) }, 15000);
method 2:
var cursor = collection.find({}, {snapshot: true}); cur.nextobject(function(err, item) { console.log("read first doc alone", item) }) //i made sure insert new document collection before below timer fires settimeout(function(){ cursor.each(function(err, docu){ console.log("cursor items", docu); }) }, 15000);
for both methods, started application, within next 15 secs inserted row same db manually.
method 1 outputs rows exists , row inserted in 15 secs.
method 2 outputs first row , method not printing row inserted in 15 secs, irrespective of {snapshot: true} or {snapshot: false}
questions
- why '
snapshot
' option offind
method not working in method 1 - giving
{snapshot: true}
or{snapshot: false}
in method 2 not prints document inserted manually. - please let me know site, explains behavior of cursors.
tried per @scott hernandez below, newly inserted documents coming in snapshot cursor.
var simpleschema = new mongoose.schema({ name:{type:string} }, {collection:'simple'}); var simplemodel = mongoose.model('simplemodel', simpleschema); //var snapshotquery = simplemodel.find({}).setoptions({snapshot:true}); //try method 1 var snapshotquery = simplemodel.find({}).snapshot(true); //try method 2 settimeout(function(){ snapshotquery.exec(function(err, docs){ if(err){ console.log("error", err); }else{ console.log("settimeout", docs); } }) },10000)
the format incorrect. must use snapshot method described in docs.
Comments
Post a Comment