3

Using mongoose-Plugin within an node.js-app will openes more than just one connection, even if im only calling mongoose.connect(...); just one single time. How could that be?

Heres my terminal output from mongod which proves that more than one connection are incomming

NETWORK  [initandlisten] connection accepted from 127.0.0.1:51515 #1 (1 connection now open)
NETWORK  [initandlisten] connection accepted from 127.0.0.1:51516 #2 (2 connections now open)
NETWORK  [initandlisten] connection accepted from 127.0.0.1:51517 #3 (3 connections now open)
NETWORK  [initandlisten] connection accepted from 127.0.0.1:51518 #4 (4 connections now open)
NETWORK  [initandlisten] connection accepted from 127.0.0.1:51519 #5 (5 connections now open)
EchtFettigerKeks
  • 1,692
  • 1
  • 18
  • 33

1 Answers1

1

As the comment from @Blakes Seven suggests the following question is a very similar one and also contains the answer to this one:

How to manage mongodb connections in a nodejs webapp

Mongoose seems to open more than just on single connection since it provides a connection-tool-functionality (see other question for more informations).

Community
  • 1
  • 1
EchtFettigerKeks
  • 1,692
  • 1
  • 18
  • 33
  • 1
    Hmm, not really. node.js uses connection pooling for every MongoClient connection. This means that an app can load balance across those connections instead of having a single threaded connection waiting and responding in a timely manner. In fact that accepted answer doesn't make much sense really. It talks about pooling from the creator (which is quite right) and then the answerer himself talks about some random subject of opening and closing connections – Sammaye Aug 19 '15 at 11:06
  • 1
    It is also good to note that since node.js runs as a deamon with the outer most script never exiting, if you put your connection in there the connections will persist across requests as well. So this allows the entire app to use multiple connections for multiple requests. Of course, if you read into this you may find you need to change the pooling for larger apps, which the accepted answer does not seem to understand either from what the primary commiter said – Sammaye Aug 19 '15 at 11:13