Skip to content

manishsaraan/mongodb-service

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published