簡體   English   中英

使用Java / Groovy讀取MongoDB oplog

[英]Reading MongoDB oplog with Java/Groovy

這個問題已經反彈了一下,我保證我會盡力使用以前的答案:)

使用Mongo Shell,我可以使用oplog中的find和see所有文檔。 但是,如果我嘗試使用find()通過java訪問,它將返回null。 我什至只是嘗試使用count()並返回0。

//this does indeed return oplog.rs as a valid collection
def collections = db.getCollectionNames();
println(collections);

DBCollection coll = db.getCollection("opslog.rs")

DBCursor cursor = coll.find();

while(cursor.hasNext()) {
println("something here" + cursor.next())
}

似乎一無所獲。 或者,如果我只是嘗試打印出我得到的光標: 光標id = 0,ns = local.opslog.rs,query = {},numIterated = 0,readPreference = primary我在另一個集合上運行了相同的代碼,它可以工作。 我必須在Java / Groovy中以不同的方式對待oplog嗎? 如果可用的話,任何Java示例都很棒。

**順便說一句-我嘗試訪問'local',system.replset和startup_log中的其他兩個集合,並能夠取回數據。

謝謝,如果我在搜索中錯過了此答案,請提前致歉。

您的代碼中有錯別字, opslog.rs應該是oplog.rs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM