Having recently migrated Graticule’s backend to MongoDB 3 (which was surprisingly easy), I’ve noticed a lot of the methods used in the Java driver have been deprecated.

Most of them were easy to figure out, but tailable cursors presented a bit of a challenge.

I haven’t been able to find a clear-cut example online, so here’s one:

find(query).projection(fields).cursorType(CursorType.TailableAwait).iterator();

That code applies to the MongoCollection class.

CursorType is an enum and it has the following values:

  • Tailable
  • TailableAwait

Corresponding to the old DBCursor.addOption Bytes types:

  • Bytes.QUERYOPTION_TAILABLE
  • Bytes.QUERYOPTION_AWAITDATA

I hope that helps.

Happy coding!