1.5.1 • Published 2 years ago

@imtiazchowdhury/mongopool v1.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

connect-mongo

Connect to mongoDB and re-use the connection to benefit from mongoDB node driver's connection pooling

    import mongoClient from "@imtiazchowdhury/mongopool"

    //this setup has to be done once only, preferrably in the application root like app.js file
    mongoClient.url = "mongodb://127.0.0.1:27017" // mongodb url
    mongoClient.dbName = "YOUR_DB_NAME"

    ...

    //whenever you need db instance
    const db = await mongoClient.getDB()
    const result = await db.collection("COLLECTION_NAME").findOne({...})

    ...

Installation

npm install @imtiazchowdhury/mongopool