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 6173371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:33:38+00:00 2026-05-23T23:33:38+00:00

I have 2 collections: A (3.8M docs) and B (1.7M docs) I have a

  • 0

I have 2 collections: A (3.8M docs) and B (1.7M docs)

I have a PHP script that I run from the shell that:

  1. loops over each record in A
  2. ~60% of the time, it does a findOne on B (using _id)
  3. does some basic math, creating a php array

once the loop on all docs in a is done:

4) loop over php array

5)upsert into collection C

during (1), I consistently get: PHP Fatal error: Uncaught exception ‘MongoCursorException’ with message ‘Cursor not found’
The last item processed was #8187 of 3872494.

real    1m25.478s
user    0m0.076s
sys     0m0.064s

Running it again, with no change in code, the exception got thrown at item #19826 / 3872495

real    3m19.144s
user    0m0.120s
sys     0m0.072s

And again, #8181 / 387249

real    1m31.110s
user    0m0.036s
sys     0m0.048s

Yes, I realize that I can (and probably should) catch the exception… but… why is it even being thrown? Especially at such different elapsed time/depth into the database.

If it helps, my setup is a 3-node replica set (2+arb). I took the secondary offline and tried with just the primary running. Same results (different number of results processed and times, but always throws the Cursor Not Found exception).

  • 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-05-23T23:33:39+00:00Added an answer on May 23, 2026 at 11:33 pm

    Yes, I realize that I can (and probably should) catch the exception…

    Yes, this is definitely the first thing to do. There are dozens of legitimate reasons for an exception to happen? Heck what do you think happens when the primary goes off-line and becomes unreachable?

    … why is it even being thrown?

    There are a couple of potential reasons, but let’s cut straight to the error code you’re seeing.

    • Official PHP docs are here.
    • Quote from that page: The driver was trying to fetch more results from the database, but the database did not have a record of the query. This usually means that the cursor timed out on the server side…

    The MongoDB PHP driver has two different timeouts:

    • Connection timeout
    • Cursor timeout

    You’re hitting a cursor timeout. You can connect to the DB, but your query is “running out of time”.

    Possible fixes:

    1. Extend the cursor timeout. Or you can set it to zero and make it last forever.
    2. Do this job in batches. Get the first 1000 _ids from A, process them and then mark that you have done so. Then get the next 1000 _ids greater than your last run and so on.

    I would suggest #2 along with handling the exception. Even if these doesn’t completely solve the problem it will help you isolate and mitigate the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do Java collections have a built-in method to return multiple items from that collection?
In many places in our code we have collections of objects, from which we
In Mongo my understanding is that you can have databases and collections. I'm working
I'm trying to create script, that will import keywords from images to database. Keywords
The MongoDB docs seem good overall, the only issue I have is that it
I am working on a BlackBerry j2me Java implementation that does not have the
We have a bunch of cli cron style scripts that are coded in php.
I have several document collections that occasionally need to be pulled together into a
I have two collections which have property Email in both collections. I need to
I have a collection of collections, all the child collections have the same number

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.