I am trying to implement a tailable cursor for mongo using C driver. Uptil now i have been able to create it and successfully get the pushed data into my process with the following code
cursor =mongo_find( connection, DB_TENANT_NAMESPACE, query, bson_empty( &e ), 0, 0, MONGO_TAILABLE | MONGO_AWAIT_DATA);
while(1)
{
while(mongo_cursor_next(cursor) == MONGO_OK)
{
b=mongo_cursor_bson(cursor);
if(bson_find(iterator,b,"_id"))
{
oid =bson_iterator_oid(iterator);
bson_oid_to_string(oid,&id);
printf("ID:%s\n",id);
}
}
With this code i can get the updates. But looking at the tailable cursors docs, it seems that i need to run the mongo_find inside the outer while loop to make sure i get the latest entries. The docs suggest appending to query with gte. Copying from docs
query = QUERY( "_id" << GT << lastId ).sort("$natural");
The issue is that the oid is an object which can be converted to a string. I dont really think i should be converting it to an int in-order for gte to work. Any ideas?
ObjectId’s may be logically compared by those operators, as can Date and Timestamp objects. There should be no need to represent the ObjectId as a string, and is no practical reason (at least in this case) for comparing an ObjectId to a string.
Note that comparisons involving two different BSON types will follow this compare order.