1.0.1 • Published 6 years ago

mongodb-service v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

mongodb-service

A service to perform mongoose queries with promises.

version MIT License XO code style

Note : Populate support will be added soon.

How to use

You can use this module by passing the query, model as params.

Insert

const ms = require('mongodb-service');
const userObj = {
  fname: 'first',
  lname: 'last',
  username: 'testusername',
  email: 'test@gmail.com'
};

ms.create(userObj, TestModel)
      .then(data => {
        //success response
      })
      .catch(err => {
       //handle error
});

findOne

Get one record from the db.

ms.findOne({username: userObj.username}, TestModel)
   .then(data => {
     //handle success
   })
   .catch(err => {
     //handle error
});

Update

Update a record in db. You have to pass query, update query and model for this operation.

ms.update({username: userObj.username}, {$set: {username: 'updatedusername'}}, TestModel)
    .then(data => {
      //handle success
    })
    .catch(err => {
      //handle errror
});

findAll

Get all the documents from db.

 ms.findAll({username: userObj.username}, TestModel)
    .then(data => {
     //handle success
    })
    .catch(err => {
     //handle error
});

Delete

Remove one/all documents.

ms.delete({username: 'updatedusername'}, TestModel)
    .then(data => {
    //handle success
    })
    .catch(err => {
    //handle error
});