我正在使用mongo-oplog包来创建mongodb的插入侦听器。
var MongoOplog = require('mongo-oplog');
var oplog = MongoOplog('mongodb://127.0.0.1:27017/local').tail();
oplog.on('op', function (data) {
console.log(data);
});
oplog.on('insert', function (doc) {
console.log(doc.op);
});
oplog.on('error', function (error) {
//catch the error -> do nothing
});
结果,我得到了这种格式的回复:
{ ts: { _bsontype: 'Timestamp', low_: 1, high_: 1437408655 },
h: { _bsontype: 'Long', low_: -681831757, high_: 1089307960 },
v: 2,
op: 'i',
ns: 'mongoapp.British',
o:
{ _id: 55ad1d8f2d98983c1d15413a,
user: 'lalala',
language: 'en',
location: '',
time: 'Mon Jul 20 16:10:54 +0000 2015',
text: 'First the flight was delayed and now my luggage is missing #britishairways.' } }
i
我的问题是:有没有办法解析这个?我希望能够解析文本字段以进行更改。这可能吗?