@mongodb-helpers/connect
v0.2.1
Published
Don't repeat yourself when you want to connect to mongodb π§π»ββοΈ.
Downloads
13
Maintainers
Readme
@mongodb-helpers/connect
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