MongoDB Tailable Cursors in C# - mongodb

How to create a tailable cursor on a mongodb capped collection with the C# driver?

I don't believe this feature is currently implemented in the C# driver.
https://jira.mongodb.org/browse/CSHARP-219
You should be able to add a watch to that item which will let you know when it's done.

Related

Is it possible to retrieve the query mongodb compass uses when I visually modify a document?

I'm new to mongodb, and therefore it is still hard for me to create queries on my own. I found mongodb compass helpful to modify my documents, but would like to have queries in order to apply changes quicker to the production database.
Is there a way to modify a document visually using mongodb compass and then to get the query that mongodb compass uses behind the curtain?
If not, is there some different GUI application that could help me to create queries?

Tailable cursor vs Change streams for notifications of insert operations in capped collections

I am curious about the benefits and drawbacks of using a tailable cursor versus a change stream with filter for insert operations over a capped collection both in usability and performance-wise.
I have a capped collection that contains update objects. The only possible operation for this collection is insertion of new updates(as new records) which I need to relay to my application backend and distribute through SSE/WebSockets in real-time. I'll use a single parameter in the query for subscription and it is a timestamp which is part of the object's properties. The collection has an index on that field. I'll also do some basic filtering over the newly added records, so the aggregation framework of Change Streams would be helpful.
I've read: What is the difference between a changeStream and tailable cursor in MongoDB which summarizes the differences between tailable cursors and change streams in general.
Also, the mongodb article on Capped Collections just states the Tailable cursor approach and the article on Tailable cursors state that they do not use indexes and you should use a normal cursor to fetch the results.
In short, I need a reliable stream of collection updates based entirely on the insertion of new records in the collection. Which approach should I go for?
Tailable cursors and capped collections were created to support copying the oplog from a primary node to a secondary node. For any other activity the recommended approach is a ChangeStream. Change streams are integrated with the MongoDB authentication model and a change stream can be take at the collection, database, cluster and sharded cluster level. Tailable cursors only work on a single collection and are not resumable. Change streams are supported by all official MongoDB Drivers.

MongoDB aggregation query in RapidMiner

How to do an aggregation query in MongoDB from the RapidMiner using the mongodb plugin? I've tried to google around, unfortunately with no success at all. It has a direct support for criteria and projection (using operator "Read MongoDB"), however I don't see anyhow support for the aggregation. It does have an "Execute MongoDB Command" operator, which might be capable of doing that but I can't find any extensive examples on how to use it. Eventually, if the above mentioned is not possible, do you know any other way how to do the "unwind" over the data in the RapidMiner having the mongodb collection loaded in?
The Execute MongoDB Command Operator is a wrapper for the mongoDB command db.runCommand(). If you want to continue working in RapidMiner, you can expand the collection you get as a result from the Read MongoDB and transform it into an ExampleSet with the JSON to Data Operator.

poll addition of new object in mongodb collection

I have a python script which needs to do some actions whenever a new object is added in a collection
is there any efficient method to poll for addition of new object in mongodb collection?
Have a look at mongodb 'tailable' cursor.
http://www.mongodb.org/display/DOCS/Tailable+Cursors
Use "find" method of your python driver with "tailable" = true,
it will keep realtime track of additions in the database just like "tail -f" of a file in linux .
Tailable is FALSE by default.
http://api.mongodb.org/python/current/api/pymongo/collection.html
find([spec=None[, fields=None[, skip=0[, limit=0[, timeout=True[, snapshot=False[, tailable=False[, sort=None[, max_scan=None[, as_class=None[, slave_okay=False[, **kwargs]]]]]]]]]]]])
tailable (optional): the result of this find call will be a tailable cursor - tailable cursors aren’t closed when the last data is retrieved but are kept open and the cursors location marks the final document’s position. if more data is received iteration of the cursor will continue from the last document received. For details, see the tailable cursor documentation.
use a separate thread to poll the data. It is less efficient but works..
the alternative solution is to use twisted and its async driver but you still need to poll
the data.

How to create tailable cursor in MongoDB shell?

I would like to create an endless processing loop for capped collection directly in MongoDB, but I can't find how I can get tailabale cursor in MongoDB shell. It's possible in Python with tailable option in Collection.find() though..
You can add the option after find() using addOption():
db.coll.find().addOption(2) // probably want to use 2(tailable) + 32(await_data)
See all the options here: http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPQUERY
You will want to put this in a loop as even tailable cursors (w/await_data) return no results sometimes.