0

I am making use of the NodeJs MongoDB driver for my current project, I have 3 collections and counting. On each collection, I notice that a new connection is created per collection. For example, Users collection makes a separate connection to MongoDB, Comments collection also makes its own separate connection to MongoDB. I am just curious if this is normal? This is my first time using the MongoDB NodeJs Driver instead of Mongoose. I have separate Javascript files that handles database interaction for each collection, and these files makes its own call to the database to perform some basic crud operations, is there any other way I can make this efficient or is this normal?

thatguy
  • 370
  • 1
  • 5
  • 22
  • Have you read https://stackoverflow.com/questions/24621940/how-to-properly-reuse-connection-to-mongodb-across-nodejs-application-and-module – Wyck Jul 13 '20 at 13:23
  • Usually a single connection object is created, which creates a connection pool, and is used throughout the application. See [Connection Settings](https://mongodb.github.io/node-mongodb-native/3.6/reference/connecting/connection-settings/). – prasad_ Jul 13 '20 at 13:26
  • Thank you, both responses seemed to solve the issue. – thatguy Jul 13 '20 at 15:08

0 Answers0