mongodb-connection-simple

1.2.0 • Public • Published

mongodb-connection

MongoDb Implementation that uses the same connection to save some performance. It is intended to be used as a singleton.

How to install

npm install --save mongodb-connection

MongoDbConnection

Main implementation class.

Parameters:

  • servers: An array of objetcs with server information (Example: { host: 'localhost', port: 27017}) or the mongodb uri
  • databaseName: Name of the database to connect.
  • options: MongoDB client options

Methods

  • connect(options): Verifies if there is not a current connection and creates one if there is not.

Example - Promise

async function method(){
    await mongodb.connect();
    const collection = mongodb.database.collection('test');
    return await collection.find();
}

Dependencies (4)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i mongodb-connection-simple

    Weekly Downloads

    1

    Version

    1.2.0

    License

    ISC

    Unpacked Size

    12.5 kB

    Total Files

    9

    Last publish

    Collaborators

    • franciscojsucreg