Tailable cursors, filtering and sorting

333 views
Skip to first unread message

rg

unread,
Aug 22, 2012, 4:10:06 PM8/22/12
to mongod...@googlegroups.com
Hi, i'd like to use MongoDB as a message queue and thought about using a capped collection + tailable cursor for that purpose.
I know that the tailable cursor can be used for accessing documents in the insertion order but
1. can I use any sort order for the cursor?
2. does a tailing cursor work with a filter query (to skip some documents I don't want to process)? If so, how does it handle insertion of new documents - will I be notified only if the new document matches the query criteria?
3. Are tailing cursors fully supported by C# driver?
4. I'd like my queue to guarantee single delivery - I mean if two clients try to read messages from the same collection they shouldn't be able to 'consume' the same message. I think this could be achieved with findAndModify, but how to do that with tailing cursor?

Thanks 
RG

Stephen Steneker

unread,
Aug 23, 2012, 2:53:25 AM8/23/12
to mongod...@googlegroups.com
Hi, i'd like to use MongoDB as a message queue and thought about using a capped collection + tailable cursor for that purpose.

Hi RG,

There was a presentation from AOL/About.me on "MongoDB as message queue" at the Silicon Valley MUG in April that you may find helpful:

I know that the tailable cursor can be used for accessing documents in the insertion order but
1. can I use any sort order for the cursor?
2. does a tailing cursor work with a filter query (to skip some documents I don't want to process)? If so, how does it handle insertion of new documents - will I be notified only if the new document matches the query criteria?

A tailable cursor tails the *end* of a capped collection and only in natural order.  If you want a sort order you need to use an indexed query instead.

Please have a read of the Tailable Cursor wiki page for more information:
   http://www.mongodb.org/display/DOCS/Tailable+Cursors

3. Are tailing cursors fully supported by C# driver?

Yes, tailable cursor support was implemented in the 1.1 C# driver.  A code example: http://www.pastie.org/1977343.
 
4. I'd like my queue to guarantee single delivery - I mean if two clients try to read messages from the same collection they shouldn't be able to 'consume' the same message. I think this could be achieved with findAndModify, but how to do that with tailing cursor?

Based on your use case, I don't think tailable cursors would be a helpful approach.

For info on atomic operations see: http://www.mongodb.org/display/DOCS/Atomic+Operations 

Cheers,
Stephen
Reply all
Reply to author
Forward
0 new messages