6

I had been wondering about knowing mongoDB changes instantly for a while and best solution that I have ever seen, is tailing mongoDb logs and I just had given wondering up till met Meteor.

When there is a changes on mongoDB somehow(through Meteor or directly), Meteor understands the changes instantly and apply them. We could see it on publishing changes or observing(observe or observeChange) changes.

I guess that, Meteor could understand it by tailing mongoDB logs as the best solution that I have ever seen suggests. But this assumption also make me ask that, Meteor can run with a mongoDB running on different host and if the way that meteor knows MongoDB changes instantly is tailing logs, how could Meteor tails logs of mongoDB running on different machine(different host) and handle changes? Tailing on different host requires painful things and I think Meteor does not follow this way.

I think tailing logs is not my answer because of this question.

I am curious about this knowledge. Cause, I think that, if I have it, I could use it on my other works without Meteor.

So, how could really Meteor knows mongoDB changes instantly? And I wanna ask once again; what would be the best way to know about mongoDB changes instantly?

Thank You!

1 Answer 1

8

Yes you are right this is from new new oplog tailing functionality. Meteor pretends that it is mongodb in a replica set and it tails mongodb's operation logs for collections it is monitoring.

Usually databases need multiple servers so that they can stay up in case one fails. MongoDB has this functionality in a replica set.

So this is where meteor comes in. Meteor pretends to be a mongodb replica database so when any data changes on this operations log for other copies to see, Meteor knows that data has changed and can push this new data down to the client instantly.

Usage in production

You can use a different mongo database with this new functionality as you set MONGO_OPLOG_URL. You will need to set mongodb as a replica set first so that the operations log is enabled

This was a very recent introduction put in just last week in version 0.7 you can see the blog post about it below

More links about it:

4
  • I wanna ask that Do you mean that Meteor was not able to aware about direct changes on DB(not through Meteor) instantly? So this was not available before 0.7, right?
    – Ahmet DAL
    Dec 23, 2013 at 14:16
  • 2
    @AhmetDAL it was available but it was a poll-and-diff algo. So the changes did come in but to a maximum of 10 seconds late. (Meteor would poll the database every 10 seconds)
    – Tarang
    Dec 23, 2013 at 14:17
  • 1
    Wow, then the changes about oplog is so critical.
    – Ahmet DAL
    Dec 23, 2013 at 14:22
  • What if I use GraphQL with meteor? Will it know database changes behind GraphQL instantly?
    – Zhang Buzz
    Sep 26, 2016 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.