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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:31:57+00:00 2026-05-24T23:31:57+00:00

In short: There is a huge difference in insert speeds when I keep a

  • 0

In short: There is a huge difference in insert speeds when I keep a JSON object with many fields in a single, string field of MongoDB, or keep each field of the JSON object in its own MongoDB field. 1) Is this difference normal? 2) Are these insertion speeds typical?

I have many records each with a unique string id and 600 integer values. They are already represented as JSON objects in a file — each document on a separate line. If I represent a MongoDB document as a collection of integer fields and put my unique id into the _id field of MongoDB, I can insert around 50 documents per second. If I instead create a document with only two fields (_id for the unique string id, and val as a single string which keeps the entire JSON line of the record) I can insert around 100 documents per second.

I am using the Python client and have tried doing batch inserts (e.g., 10, 100, 1000 at a time). The difference is always there. Is this behavior expected? I naively assumed that I wouldn’t see a difference because MongoDB itself keeps the records as BSON and there really shouldn’t be much difference between having 600 fields each with an integer or a single string which contains a JSON record which, in turn, keeps 600 integers.

Addendum: 1) I do the conversion from JSON to a dictionary in both cases, to make sure it’s not affecting the speed measurement(i.e., json.loads and other stuff). In other words, in the single-field-with-JSON-string case, I do everything I do in the other case, but ignore the converted dictionary.

2) I also tried a dry-run, everything intact without any insert to MongoDB. I can process around 700-800 lines per second.

3)

a. db.test.stats() in single-line-single field case (i.e. fast case):
{
    "ns" : "tmp.test",
    "count" : 7999,
    "size" : 71262392,
    "avgObjSize" : 8908.91261407676,
    "storageSize" : 88751616,
    "numExtents" : 9,
    "nindexes" : 1,
    "lastExtentSize" : 21742848,
    "paddingFactor" : 1,
    "flags" : 1,
    "totalIndexSize" : 466944,
    "indexSizes" : {
        "_id_" : 466944
    },
    "ok" : 1
}

b. db.test.stats() (each column to a separate case; i.e., slow case):
{
    "ns" : "tmp.test",
    "count" : 7999,
    "size" : 85710500,
    "avgObjSize" : 10715.15189398675,
    "storageSize" : 107561984,
    "numExtents" : 9,
    "nindexes" : 1,
    "lastExtentSize" : 26091264,
    "paddingFactor" : 1,
    "flags" : 1,
    "totalIndexSize" : 466944,
    "indexSizes" : {
        "_id_" : 466944
    },
    "ok" : 1
}
  • 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-24T23:31:57+00:00Added an answer on May 24, 2026 at 11:31 pm

    If possible, enable the C extensions, as they will provide a significant performance improvement. I think the difference in speed is due to the larger number of keys that must be serialized (by pure-Python code, since you have the extensions disabled) into the BSON document. With the C extensions enabled, this will be much faster (but must still be done), so I suspect you will still see a (very slight) difference in speed between the two approaches.

    Edit: Note that when I say “enable the C extensions,” I mean re-build pymongo, or use a pre-built binary for your platform that has the C modules built. You can see the available binary packages at http://pypi.python.org/pypi/pymongo/2.0.1#downloads

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

Sidebar

Related Questions

In short: Is there any known protocol for remote process management? I have a
Short Version: Is there a/what is the suggested way to return error details to
short version: Is there a good time based sampling profiler for Linux? long version:
Is there a short way to check/get for least significant bit in a 32-bit
The short version: is there a way to to write an and or an
Is there any keyboard short cut to compile selected file in C++ project in
Short version question : Is there navigator.mozIsLocallyAvailable equivalent function that works on all browsers,
Short of copying the entire .netbeans directory is there any way to transfer custom
Short of rolling your own. There has to be something out there. FlexLM/FlexNet is
Is there a search API for getting a short text containing the search terms

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.