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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:16:30+00:00 2026-05-26T22:16:30+00:00

Before I dive into my question, I wanted to point out that I am

  • 0

Before I dive into my question, I wanted to point out that I am doing this partially to get familiarized with node and mongo. I realize there are probably better ways to accomplish my final goal, but what I want to get out of this is a general methodology that might apply to other situations.

The goal:

I have a csv file containing 6+ million geo-ip records. Each record contains 4 fields in total and the file is roughly 180mb.

I want to process this file and insert each record into a MongoDB collection called “Blocks”. Each “Block” will have the 4 fields from the csv file.

My current approach

I am using mongoose to create a “Block” model and a ReadStream to process the file line by line. The code I’m using to process the file and extract the records works and I can make it print each record to the console if I want to.

For each record in the file, it calls a function that creates a new Blocks object (using mongoose), populates the fields and saves it.

This is the code inside of the function that gets called every time a line is read and parsed. The “rec” variable contains an object representing a single record from the file.

block = new Block();

block.ipFrom    = rec.startipnum;
block.ipTo      = rec.endipnum;
block.location  = rec.locid;

connections++;

block.save(function(err){

    if(err) throw err;
    //console.log('.');
    records_inserted++;

    if( --connections == 0 ){
        mongoose.disconnect();
        console.log( records_inserted + ' records inserted' );
    }

});

The problem

Since the file is being read asynchronously, more than one line is processed at the same time and reading the file is much faster than MongoDB can write so the whole process stalls at around 282000 records and gets as high up as 5k+ concurrent Mongo connections. It doesn’t crash.. it just sits there doing nothing and doesn’t seem to recover, nor does the item count in the mongo collection go up any further.

What I’m after here is a general approach to solving this problem. How would I cap the number of concurrent Mongo connections? I would like to take advantage of being able to insert multiple records at the same time, but I’m missing a way to regulate the flow.

Thank you in advance.

  • 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-26T22:16:30+00:00Added an answer on May 26, 2026 at 10:16 pm

    I would try the commandline CSV import option from Mongodb – it should do what you are after without having to write any code

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

Sidebar

Related Questions

Just wanted to know before I dive into this field. Is it possible to
Before I dive into the question. Let me state that by Event Loop I
Now before I dive too far into this this question, I am aware of
This is just a quick question before I dive deeper into converting my current
Before I dive into the disscusion part a quick question; Is there a method
I'm new to iOS and objective-C. Before I dive down into this I'd like
Before I dive into development, I want to know if this is possible at
This is my first real dive into JavaScript. Sure I've used it before, but
Before I dive into ANTLR (because it is apparently not for the faint of
Before I dive into ASIHttpRequest's source code: From the documentation ( http://allseeing-i.com/ASIHTTPRequest/How-to-use ) of

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.