Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:30:47+00:00 2026-06-17T13:30:47+00:00

I am a beginner in Haskell and I tend to learn by doing. Could

  • 0

I am a beginner in Haskell and I tend to learn by doing.

Could someone provide me an example of how to use the cursor with nextBatch or nextN?
http://hackage.haskell.org/packages/archive/mongoDB/1.3.1/doc/html/Database-MongoDB-Query.html#g:12

Tried something like this (I tried to write a custom iteration function, where f is a function which I want to map over all documents)

let cursor = Mdb.find (Mdb.select selector collection)
       -- consume :: IO ()
       consume = do
                r <- runAction db $ Mdb.nextBatch =<< cursor
                if length (fromRight r) == 0
                    then return ()
                    else do
                        mapM_ f (fromRight r)
                        consume
   consume

Now this runs in an infinite loop, always returning the same set of documents. I guess the cursor is never being modified? The cursor type itself has an MVar as one of it’s elements, first I thought that would be updated when I do a nextBatch, but that never happens.

Maybe I should rewrite the recursion the way it stays in the Action monad (see mongo driver), rather than IO? I am stuck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:30:48+00:00Added an answer on June 17, 2026 at 1:30 pm

    When you write let cursor = Mdb.find (Mdb.select selector collection) it creates Action m Cursor that will be executed only in Action m context, so actually you created new cursor each =<< cursor time.

    Yes, i think that you should rewrite you function in mostly Action m context. For example:

    consume :: IO ()
    consume = void $ runAction db $ do
        cursor <- Mdb.find $ Mdb.select selector collection
        go cursor
      where
        go cursor = Mdb.nextBatch cursor >>= \result -> case result of
            [] -> return ()
            xs -> mapM_ f xs >> go cursor
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner with Haskell, so it might be very obvious what I'm doing
I am a beginner with haskell and am reading the Learn you a haskell
I'm playing around with beginner Haskell, and I wanted to write an average function.
I am a beginner of Haskell. What is wrong with this expression?: Prelude> let
I am a beginner in Haskell so please bear with me. (Just started learning
Beginner help needed :) I am doign an example form a php book which
I am a beginner interested in Haskell, and I have been trying to implement
While solving some Project Euler Problems to learn Haskell (so currently I'm a completly
I am a beginner to Haskell. I just wonder how to implement a function
I am a beginner, and write implementation of hangman in haskell. Necessary to show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.