[DOCS-919] add JavaScript TailableCursor example Created: 20/Dec/12  Updated: 13/Feb/13  Resolved: 13/Feb/13

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: v1.1

Type: Task Priority: Major - P3
Reporter: Kay Kim (Inactive) Assignee: Kay Kim (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 11 years, 1 week ago

 Description   

This example kind of works but is missing the handling of a dead cursor:

var coll = db.myCappedCollection;
var startDoc = coll.find().hint(

{ '$natural': 1 }

).limit(1).next();
var lastValue = startDoc['insertDate'];
printjson(startDoc)
var cursor = coll.find( { 'insertDate' :

{ '$gt' : lastValue }

}
).hint(

{ '$natural': 1 }

).addOption( DBQuery.Option.tailable ).addOption( DBQuery.Option.awaitData );

while (1) {
try {
if ( cursor.hasNext() )

{ var doc = cursor.next(); lastValue = doc['insertDate']; printjson(doc); }

} catch (e)

{ break; }

}



 Comments   
Comment by Kay Kim (Inactive) [ 13/Feb/13 ]

shell doesn't have a way to get cursorid to test for dead cursor (cursorid=0)

Generated at Thu Feb 08 07:39:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.