【发布时间】:2017-08-23 22:51:30
【问题描述】:
我正在尝试无限期地跟踪 mongo oplog 集合。我目前使用的代码如下。
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();
我正在尝试使用 spring-data 获得相同的实现,其中将在属性文件中指定 mongo uri。因此我需要访问 MongoDatabase 或 MongoClient。
在 spring 中尝试使用 MongodbFactory 类,但它返回了一个 DB 类型的实例,这是访问 mongo 的旧 mongo 实现。
如何使用 Spring Data 使用 MongoDatabase/MongoCollection/MongoClient。
【问题讨论】:
-
Google 是你的朋友。
-
阿比吉特·萨卡尔。我只是在搜索后才在这里问了一个问题。如果您觉得在 google 中得到这个答案很简单,那么为什么不在这里提供答案。
-
刚刚做了,我用了不到 10 分钟。我之前没有这样做的原因是因为你没有表现出任何努力。
标签: spring mongodb spring-data spring-data-mongodb