0
votes

I have a stand-alone node.js application which performs a large number (10k+) of Mongo queries using Mongoose in an asynchronous way.

The queries are created is a very short time - does this mean that Mongoose does send all the eg. 10k queries to the database at the same time?

I read that Mongoose uses by default 5 connections - does this limit the number of parallel requests to 5 or can Mongoose query multiple async requests at the same time through each connection?

If multiple requests can be performed at the same time - how to I throttle my app so that it does not overloads the Mongo database?

1

1 Answers

2
votes

No, this doesn't limit it to 5. You need something to control the async flow such as async library. You're not providing any code, so I'm not sure exactly which one to use but one of these should fit your need:

// pass limit = 5
async.eachLimit()  
async.everyLimit() 

or process one by one with

async.eachSeries() // kind of like sync forEach
async. whilst()    // kind of like while loop