Skip to content

mongodb-helpers/connect

Repository files navigation

@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

About

Don't repeat yourself when you want to connect to mongodb 🧚🏻‍♂️.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published