MongoDB Documentation, Release 3.0.4 A dead cursor has an id of 0 . See your driver documentation for the driver-specific method to specify the tailable cursor. The tail function uses a tailable cursor to output the results from a query to a capped collection: C++ Example • The function handles the case of the dead cursor by having the query be inside a loop. • To periodically check for new data, the cursor->more() statement is also inside a loop. • Initialize the lastValue variable, which tracks the last accessed value. The function will use the lastValue if the cursor becomes invalid and tail needs to restart the query. Use hint() to ensure that the query uses the $natural order. • In an outer while(1) loop, The tail function performs the following actions: 124 Chapter 3. MongoDB CRUD Operations #include "client/dbclient.h" using namespace mongo; / * * Example of a tailable cursor. * The function "tails" the capped collection (ns) and output elements as they are added. * The function also handles the possibility of a dead cursor by tracking the field 'insertDate'. * New documents are added with increasing values of 'insertDate'. * / void tail(DBClientBase& conn, const char * ns) { BSONElement lastValue = minKey.firstElement(); Query query = Query().hint( BSON( "$natural" << 1 ) ); while ( 1 ) { auto_ptr<DBClientCursor> c = conn.query(ns, query, 0, 0, 0, QueryOption_CursorTailable | QueryOption_AwaitData ); while ( 1 ) { if ( !c->more() ) { if ( c->isDead() ) { break ; } continue ; } BSONObj o = c->next(); lastValue = o["insertDate"]; cout << o.toString() << endl; } query = QUERY( "insertDate" << GT << lastValue ).hint( BSON( "$natural" << 1 ) ); } }