mongodb-service

1.0.1 • Public • Published

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
});

Package Sidebar

Install

npm i mongodb-service

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

4.84 kB

Total Files

4

Last publish

Collaborators

  • manishsaraan