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

  • Home
  • SEARCH
  • 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 8657219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:28:05+00:00 2026-06-12T15:28:05+00:00

I’m trying to loop through all my documents in a particular collection and update

  • 0

I’m trying to loop through all my documents in a particular collection and update the document (based on information already in the document). I started out doing this in python with pymongo, but it seems to be taking forever, so i decided to move it to the db box and run it in javascript, but it still seems to stall. I’m only talking about a coup,e thousand documents. What i seem to notice is:

start the task, first 500 objects get updated right away, few moments later, next 200, a little bit longer another 100, and then it just starts to slow down further and further.

If i remove the update call from my code, it flies through the loop just fine, so obviously it seems like my update is freezing something.

Heres the js i’m running:

mydb = db.getSisterDB(DB_NAME);

var cursor = mydb.user.find({is_registered:true}).limit(3000);
while (cursor.hasNext()) {
    var u = cursor.next();
    /* fix property on user doc */
    mydb.user.update({ _id: u._id }, u);
    print(cursor.objsLeftInBatch());
}
  • 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-12T15:28:06+00:00Added an answer on June 12, 2026 at 3:28 pm

    My guess is that the first 500 objects fit into some cache, so they are updated in memory and written to disk later. But after 500 write operation the cache is full, so subsequent writes have to wait until the previous changes have been written to the disk.

    Your code reads the whole documents from the database, makes some change on them, and then sends the whole documents back to the database. This means that the whole document needs to be overwritten. It’s no miracle that this is slow.

    You should use the $set operator in your update command to update only those fields which actually changed.

    It would be even better performance-wise when you would manage to update the documents on the database without reading them into your application. You didn’t write what exactly you do with the documents and under what condition. When it isn’t that complex, this might be possible.

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

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:

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.