TonyGen/mongoDB-haskell — Issue #10: Exceptions raised when using tailable cursors
Author: mkscrg
Created: 2011-12-12 01:09:06+00:00
State: open

Suppose `accoll` is a capped collection with one document in the `test` db on localhost. (If there are no documents the server never opens the cursor anyway.) The following `ghci` session demonstrates the problem:

Prelude> :set prompt "> "
> :set -XOverloadedStrings
> :m + Database.MongoDB
> pipe <- runIOE . connect $ host "127.0.0.1"
> let query = (select [] "accoll") { options = [TailableCursor] }
> cursor <- access pipe master "test" (find query) >>= either (fail . show) return
> access pipe master "test" $ next cursor
Right (Just [ _id: 4ee551a4f19ceeeb26a9addd])
> access pipe master "test" $ next cursor
*** Exception: server returned empty batch but says more results on server

If an element is inserted and then the `next` call made again, the same exception is raised. The last call should return `Right Nothing`, and then `Right (Just [ ... ])` after an insertion.

This can be worked around by using `nextBatch` instead of `next`, but it takes two calls to get the documents back after an insert. Using `rest` or `nextN` has the same result as using `next`.