1.0.4 • Published 5 years ago

bth-mongodb-crud v1.0.4

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

Build Status Scrutinizer Code Quality Build Status Code Coverage codecov

BTH-Ramverk2 MongoDB CRUD

This is a module to handle the basic CRUD methods for a MongoDB database.

Installation

The port for the database object to communicate to the database is determined by the environment variable process.env.DBWEBB_DSN. It will default to mongodb://127.0.0.1:27017/

  1. Installation npm install bth-mongodb-crud --save

  2. Initialize

const dbObj = require(bth-mongodb-crud)('name of database')
  1. Usage

Create object

Ex:
let collection = 'users';
let object = { username: 'John Smith' };

dbObj.insert(collection, object);  // returns a promise

Delete object

dbObj.delete(collection, key, value);

Ex:
let collection = 'users';
let key = '_id';
let value = '1234567';

dbObj.delete(collection, key, value);  // returns a promise

Update object

let collection = 'users';
let key = '_id';
let value = '1234567';

dbObj.update(collection, key, value, {username: 'John Doe'});  // returns a promise

Find objects

let collection = 'users';
let criteria = {};
let projection = {};
let limit = 0; // 0 for getting all objects found.

dbObj.findInCollection(collection, criteria, projection, limit);  // returns a promise

Test

Run tests with mocha, eslint and mongodb in a docker container.

npm -run docker-mongodb

npm run test

That's it now you are all set.

Enjoy!

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago