Skip to content

raghavmecheri/MongoPooler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MongoPooler

NodeJS package to manage MongoDB connections

Installation

To install this package, navigate to your project root and run:
npm install --save mongopooler

Usage

Import the pooler wherever it needs to be used
let MongoPool = require('mongopooler');

Setup the pool in your main server file

var options = { numberOfRetries : 5, auto_reconnect: true, poolSize : 40, connectTimeoutMS: 500 };
var uri = "mongoURI"
MongoPool.createPool(uri, options);

Access the pool from wherever required, to make calls to your MongoDB

MongoPool.getInstance(function(client){
  // Perform DB operations here
})

Notes:

  • The getInstance function returns a MongoDB client object, you still have to call client.db on it to pick a database
  • getInstance will fail if it's called before createPool() is

Misc

This package is inspired by Yaki Klein's answer on this StackOverflow post.

About

NodeJS package to manage MongoDB connections

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published