@mongodb-helpers/connect
TypeScript icon, indicating that this package has built-in type declarations

0.2.1Β β€’Β PublicΒ β€’Β Published

@mongodb-helpers/connect


Build Status Coverage Status NPM version Code Size License

Don't repeat yourself when you want to connect to mongodb πŸ§šπŸ»β€β™‚οΈ.

Installation

# npm
$ npm install @mongodb-helpers/connect mongodb
# yarn
$ yarn add @mongodb-helpers/connect mongodb

When use mongoose should you also add mongoose

Usage

This is a practical example of how to use.

with MongoDB driver:

import { connect, withMongoose } from "@mongodb-helpers/connect";

const connection = await connect({ url: process.env.MONGODB_URL });
// connection.db : database instance
// connection.client: mongodb client instance
// connection.onClose: helper function to close connection

// withMongoose take mongodb client instance as param
withMongoose(connection.client);

with Mongoose ODM:

import { connect } from "@mongodb-helpers/connect/mongoose";

const connection = await connect({ url: process.env.MONGODB_URL });
// connection.db : database instance
// connection.client: mongoose client instance
// connection.mongodbClient: mongodb client instance
// connection.onClose: helper function to close connection

License


MIT Β© Imed Jaberi

/@mongodb-helpers/connect/

    Package Sidebar

    Install

    npm i @mongodb-helpers/connect

    Weekly Downloads

    1

    Version

    0.2.1

    License

    MIT

    Unpacked Size

    9.78 kB

    Total Files

    12

    Last publish

    Collaborators

    • 3imed-jaberi