Search code examples
node.jssingletonconnection-pooling

Mongodb connection pooling vs Singleton thread


I am trying to understand between using connection pooling vs using singleton connection for connecting to mongodb.

Which one is the better approach? What is difference in caching the connections in connection pooling vs instantiating a class once in singleton and using same elsewhere?


Solution

  • I suggest you to use a more high level api for interacting with Mongo. A well know one in node environment is mongoose. This library is widely used and has built in support for connection pooling, see doc. Using a high level module like mongoose can help you to boost productivity and avoid common pitfall like security bad practices etc.