I am running a large data feed into Mongo that I need to have an external client connect to and tap into the feed from the last available record - not anything older than current. I have a tailable cursor that works just fine, but it starts at the beginning of the table, and I'd like to have it start at the most recently inserted record. I know how to do this, presuming I have the _ID of the last inserted record. My problem is that I can't get findOne working properly in Java to bring back the last inserted record. Put simply, I need the Java equivalent of this Mongo JS command:
db.market.findOne( {$query:{}, $orderby:{$natural:-1}} )
There are a couple of posts on here that I've found that seem similar, but they are assuming that the client is also the one inserting the records and already have knowledge of the last available ID.
Anyways, what would the proper corresponding Java code be to accomplish the same thing - that is getting the _ID of the last available record?
I guess as an alternative I could have my client insert a throwaway record, get that ID, and start from there, but I'd prefer to do this the right way.
Thanks