Mongoose Connection Pool

In Mongoose docs, I noticed that there is support for connection pooling.

http://mongoosejs.com/docs/connections.html

Given that node is single-threaded, why is there a connection pool? What is the life cycle of the connections in the pool?

+8
mongoose
source share
1 answer

Connection pools have nothing to do with async vs sync - it just works like this:

  • You can specify the number of open connections to support your database (say, 10).
  • Every time your Node JS code makes a request, if possible, it will use one of the 10 open connections for this request so you can avoid the overhead of opening a new database connection for each request.

Maintaining a connection pool essentially supports an array of db connection objects and a selection of unused for each request. It actually does not execute threads or processes at all =)

+8
source share

All Articles