How could meteor know MongoDB changes instantly?

前端 未结 1 1863
礼貌的吻别
礼貌的吻别 2020-12-06 03:32

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 jus

相关标签:
1条回答
  • 2020-12-06 03:48

    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:

    • https://www.meteor.com/blog/2013/12/17/meteor-070-scalable-database-queries-using-mongodb-oplog-instead-of-poll-and-diff
    • https://www.youtube.com/watch?v=_dzX_LEbZyI
    • https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver
    0 讨论(0)
提交回复
热议问题