tail () { const ts = this.lastTs const nss = this.defs.map(def => def.ns) const filters = { ns: { $in: nss }, ts: { $gt: Timestamp.fromNumber(ts) } } const curOpts = { tailable: true, awaitdata: true, numberOfRetries: 60 * 60 * 24, // Number.MAX_VALUE, tailableRetryInterval: 1000 }
util.log(`Begin to watch... (from ${ts})`)
return new Promise((resolve, reject) =>
  mongodb.connect(this.url2).then(db => {
    this.db = db
    const stream = db.collection('oplog.rs').find(filters, curOpts).stream()
    stream
      .on('data', log => {
        if (log.op === 'n' || log.ts.toNumber() === ts) return
        this.process(log)
      })
      .on('close', () => {
        util.log('Stream closed....')
        this.db = null
        db.close()
        resolve()
      })
      .on('error', err => {
        this.db = null
        db.close()
        reject(err)
      })
  }))
}
目的是读取 monogodb 的 oplog 将数据同步到 mysql 里边
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.