Skip to content

PengWang0316/MongoDBHelper

Repository files navigation

MongoDB Helper

A MongoDB helper allows using MongoDB easier.

Build Status Coverage Status

Dependencies requirement

Due to this library is a wrapper for MongoDB the mongodb package is required. Please check your package.json file.

  • mongodb

Installing

npm install --save @kevinwang0316/mongodb-helper mongodb

Usage

import { initialConnects, getDB, promiseFindResult } from '@kevinwang0316/mongodb-helper';
// For NodeJS
// const { initialConnects, getDB, promiseFindResult } = require(''@kevinwang0316/mongodb-helper'');

// Initialize your connection before use it. The connection pool will be saved in a global
await initialConnects('database url', 'database name', 1);

// use promiseFindresult
const result = await promiseFindResult(db => db
  .collection('collection name')
  .find({});

// use db directly
const result = getDB().collection('collection name')
  .insert({}, (err, response) => {
    if (err) reject(err);
    resolve(response.ops[0]);
  });

Log Configuration

The @kevinwang0316/log library is using

If you want to change the defual log level (debug):

Add a log_level variable to your .env file. Or if you are using Fass solution such as AWS Lambda, set up the log_level to your environment.

Log all level of information (debug, info, warn, error) log_level=DEBUG

Log info and above levels of information (info, warn, error) log_level=INFO

Log warn and above levels of information (warn, error) log_level=WARN

Log just error level of information (error) log_level=ERROR

License

MongoDB Helper is licensed under MIT License - see the License file.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published