Exception in thread "Thread-2" com.mongodb.MongoException: Unable to execute query: error processing query: ns=local.oplog.rs limit=0 skip=0
Tree: $and
Sort: { $natural: -1 }
Proj: {}
invalid sort specified for tailable cursor: { $natural: -1 }
at com.mongodb.MongoException.parse(MongoException.java:82)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:314)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:368)
at com.mongodb.DBCursor._hasNext(DBCursor.java:459)
at com.mongodb.DBCursor.hasNext(DBCursor.java:484)
at com.trainings.core.Test.lambda$0(Test.java:32)
at java.lang.Thread.run(Unknown Source)
public static void main(String[] args) throws UnknownHostException {
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("local");
DBCollection coll = db.getCollection("oplog.rs");
DBCursor cur = coll.find().sort(BasicDBObjectBuilder.start("$natural", -1).get())
.addOption(Bytes.QUERYOPTION_TAILABLE | Bytes.QUERYOPTION_AWAITDATA);
Runnable task = () -> {
System.out.println("\tWaiting for events");
while (cur.hasNext()) {
DBObject obj = cur.next();
System.out.println(obj);
}
};
new Thread(task).start();
}