npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

drossel-mongoose

v1.2.1

Published

Unnecessary mongoose wrapper

Downloads

5

Readme

drossel-mongoose

Unnecessary mongoose wrapper

NPM

What is this?

"drossel-mongoose" add value similar to the HTTP status code, on the results of the mongoose.

Install

step1: npm install

npm install drossel-mongoose

step2: require and prepare mongoose.model

var drmg = require('drossel-mongoose');
var mongoose = require('mongoose');
var model = mongoose.model('Example', new mongoose.Schema({
  foo: { type: String },
  bar: { type: Number }
}));

Usage

Create (model, obj)

Create data.
return drossel-mongoose response, into created data object.

drmg.create(model, { foo: 'abc', bar: 123 });

Find (model, conditions)

Find data.
return drossel-mongoose response, into find data objects array. Tips: If no result, resolve "success".

drmg.find(model, { foo: 'abc' });

FindOne (model, conditions)

Find data. return drossel-mongoose response, into find data object. Tips: If no result, reject "not found".

drmg.find(model, { foo: 'abc' });

FindById (model, objectId)

Find data from ID.
return drossel-mongoose response, into find data object. Tips: If no result, reject "not found".

drmg.findById(model, 1234567890abcdef12345678);

Update (model, objectId, obj)

Update data.
return drossel-mongoose response, into updated data object.

drmg.update(model, 1234567890abcdef12345678, { foo: 'xyz', bar: 456 });

Remove (model, conditions)

Remove data.
return drossel-mongoose response, into null.

drmg.remove(model, { _id: 1234567890abcdef12345678 });

All (array)

Promise.all for drossel-mongoose.
return drossel-mongoose response.

drmg.all([
  drmg.find(model, {foo: 'foo'}),
  drmg.remove(model, {bar: 'bar'})
]);

status

return HTTP status code list.
ex) SUCCESS, NOT_FOUND, BAD_REQUEST, TEAPOT, ...

console.log(drmg.status.SUCCESS) //200

response (status, data)

return drossel-mongoose response.

drmg.response(drmg.status.SUCCESS, {
  lgtm: 'LGTM!'
}); // Promise.<{status: 200, data: {lgtm: 'LGTM!'}}>

expressResponse (res, response)

useful to Express framework.
Please refer to the example of use for more information.

Example

drossel-mongoose returns Promises.
results included status and data.

drmg.find(model, {}).then(function(result) {
  console.log(result);
});

// {
//   status: 200,
//   data: [{ foo: 'abc', bar: 123 }]
// }

If you're using the Express framework,
it can response the res.status() and res.json(), when you use the drmg.expressResponse().

var router = express.Router();
router.get('/:id?', function(req, res, next) {
  drmg.expressResponse(res, drmg.findById(model, req.params.id));
};

or, it can custom response.

var router = express.Router();
router.get('/', function(req, res, next) {
  drmg.expressResponse(res, drmg.response(drmg.status.SUCCESS, {
    lgtm: 'Looks Good To Me!'
  }));
});