0

I use the oplog in Mongoose similar to Tim Oxley's example (https://gist.github.com/timoxley/1502645).
I am looking for an efficient way to turn a newly inserted document (oplog 'i' operation) into a Mongoose document.
I tried this:
var my_model = mongoose.model('test_doc', my_schema);
// ...
function oplog_receiver(op, doc) {
if( op === 'i' ) {
doc = new my_model(doc);
doc.isNew = false;
}
// ...
doc.modified_at = new Date();
doc.save(err => {});
}

That worked well.
Is this the way to go or is there a better way of doing this?

Many thanks,
Roman

1 Answers1

0

Have you tried mongodump using --oplog? And then mongorestore using --oplogReplay?

Probal
  • 90
  • 12
  • Hello Probal, many thanks for your feedback! As far as I can see the mongodump and mongorestore commands are more offline kind of activities. What I was looking for was a way to online capture the oplog activities and make the returned objects valid Mongoose objects. The code pasted above works so far, I would like to know still if there is a more 'recommended' way to achieve this. Best regards, – RomanTheReader Jan 29 '17 at 23:19