我试图无限期地尾巴mongo oplog集合。我目前使用的代码如下。MongoDatabase与弹簧数据mongodb
MongoClient mongoClient = new MongoClient(<host>,<27017>);
MongoCollection oplogColl =
mongoClient
.getDatabase("local")
.getCollection("oplog.rs");
MongoCursor oplogCursor =
oplogColl
.find(new Document("ts", filter))
.cursorType(CursorType.TailableAwait)
.noCursorTimeout(true)
.sort(new Document("$natural", 1))
.iterator();
我试图用弹簧数据,其中蒙戈URI将在属性文件中指定,以获得相同的实现。因此我需要访问MongoDatabase或MongoClient。
在春天尝试使用MongodbFactory类,但它返回一个类型为DB的实例,这是一个用于访问mongo的旧mongo实现。
如何使用spring数据来使用MongoDatabase/MongoCollection/MongoClient。
谷歌是你的朋友。 –
Abhijit Sarkar。我只是在搜索后才提出问题。如果你觉得它很简单,在谷歌得到这个答案,那么你为什么不在这里提供答案。 – samo
刚刚做了,花了不到10分钟。我之前没有这么做的原因是因为你没有表现出你的努力。 –