1.0.16 • Published 5 years ago

@kevinwang0316/mongodb-helper v1.0.16

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

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

Log is licensed under MIT License - see the License file.

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago