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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:27:33+00:00 2026-06-14T06:27:33+00:00

I have a >6M documents collection in mongodb. And one of it’s fields (field1

  • 0

I have a >6M documents collection in mongodb. And one of it’s fields (field1 and field2 in the example below) are string values (type 2 in mongodb).

My problem is that I want to parse them into float values (all the values are parseFloat-able). I found this snippet in SO. But it doesn’t seems to be a great solution to deal with a 6M document collection.

db.collection.find({field1: {$type:1}}).forEach(function(data) {
    db.collection.update(
         {_id:data._id},
         {$set:{
              field1: parseFloat(data.field1),
              field2: parseFloat(data.field2)}
          }
    )
})

Is there any way I can convert my two fields without slowing down the server ?

Using db.collection.getIndexes() and db.collection.getIndexKeys() says that my two fields are indexed.

  • 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-14T06:27:34+00:00Added an answer on June 14, 2026 at 6:27 am

    If your goal is to prevent server slowdown then I would introduce a sleep on the client end between updates. You can adjust the timeout depending on how much load you want to reduce and your patience for the updates to complete. To force a sleep call “sleep(ms)” in the mongo shell where “ms” is the number of milliseconds you would like to sleep for.

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

Sidebar

Related Questions

I have 10000 documents in one MongoDB collection. I'd like to update all the
I have a collection of documents in MongoDB where each has one or more
tricky mongodb querying problem: I have a collection 'Accounts' with a bunch of documents
Let's assume that I have a collection in mongodb, where all of its documents
I have mongodb running and using morphia. Having a Collection of BatchData Documents and
Lets say I have collection of documents with specified longitude and latitude. type is
I have a mongo collection which has documents with two fields fieldA and fieldB,
for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
In MongoDB I have a collection of documents called 'clients', where each document is
Using PHP and MongoDB, i have a collection called users and another one called

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.