3
我想用node.js驅動程序觀察MongoDB oplog,它在理論上有效,但它具有相當大的增長時間,因爲它似乎在掃描整個集合。我發現這個在MongoDB的文檔:如何將可移動的光標移動到最後,以便我得到新的更新
- 因爲tailable遊標不使用索引,用於查詢的初始掃描可能是昂貴的;但是,在初始耗盡光標之後,隨後檢索新添加的文檔便宜。
是否有快速「排空」光標以開始拖尾的方法?在我看來,流星的人已經解決了這個問題,但是我很難理解與閱讀代碼的區別。這是我目前有:
var cursorOptions = {
tailable: true,
awaitdata: true,
numberOfRetries: -1
};
var oplogStream = oplogDb.collection('oplog.rs').find(
{
ns: { $regex : /^dbname\./ },
op: "i",
ts: { $gt: lastEntry.ts }
},
cursorOptions
).sort({$natural: -1}).stream();
oplogStream.on('data', publishDocument);
oplogStream.on('end', function() {
log.error("received unexpected end event from oplog watcher.");
});