0.2.1 • Published 4 years ago

@mongodb-helpers/connect v0.2.1

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

@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