Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

c# - With MongoDB, is it possible receive notifications of 3rd party edits via .NET Reactive Extensions (RX)?

I'm wondering if anybody knows if its possible to get live notifications of any edits to a MongoDB database via Reactive Extensions (RX) in C#?

This would mean that any 3rd party could edit the MongoDB database, and a service could monitor the edits and instantly react to them in real time.

What I have tried

I have spent a large amount of time researching this on both Google and elsewhere, and been through all of the NuGet packages that might be related. The only match I could find involved Java, and was in German.

Update 1

Looking at tailable cursors, here:

http://www.warski.org/blog/2012/11/event-streaming-with-mongodb/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How to track 3rd party changes to MongoDB data

I'm not aware of a specific Reactive Extensions implementation, however the general approach (as at MongoDB 2.6) would be to create a tailable cursor on a capped collection -- the same approach taken in the German blog post you referenced.

With a tailable cursor on the replication oplog you will get a stream of changes across all databases that you can filter by namespace and operation (insert, delete, update) as appropriate.

What if I'm not using a replica set?

While an oplog is normally only created for the purposes of replication, if you have a standalone MongoDB server you can also run it as a single node replica set with the sole benefit being the oplog.

By default, the oplog size on 64-bit systems (excepting OS X) will be 5% of free disk space. You can use the oplogSize configuration parameter to specify a different oplog size. If you don't intend to use replication, you can probably reduce the oplog size to something more suitable for your change notification. If you're not sure on an appropriate size, I would leave at the default and later follow the tutorial to Change the Oplog Size if needed.

To convert your standalone server into a single node replica set you essentially need to:

  • Add a replSet configuration value with a unique name for your replica set (and optionally, oplogSize if you want an initial size different from the default)
  • Restart your MongoDB server so this change takes effect
  • As a once off in the mongo shell, run rs.initiate() to create the replica set configuration and preallocate the oplog

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...