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

mongoose-db-shortcuts

v0.0.4

Published

mongoose database shortcuts.

Downloads

7

Readme

MONGOOSE-DB-SHORTCUTS

version 0.0.4

loading the library.

var db = require('mongoose-db-shortcuts');

db.schema

db.schema

var schema=db.schema(model_name);

db.model

db.model

var model=db.model(model_name);

db.one

db.one

db.one({
  model: 'ModelName',
  find: { _id: _id }
},function(err,res){
  // do something
});

db.count

db.count where

db.count({
  model: 'ModelName',
  where: { ... }
},function(err,res){
  // do something
});

db.count find

db.count({
  model: 'ModelName',
  find: { _id: _id }
},function(err,res){
  // do something
});

db.exists

db.exists where

db.exists({
  model: 'ModelName',
  where: { _id: _id }
},function(err,res){
  // do something
});

db.exists find

db.exists({
  model: 'ModelName',
  find: { _id: _id }
},function(err,res){
  // do something
});

db.get

complex db.get example

var _q={
  model: 'Papers',
  where: {
    $or: [
      {_id: { $in: [0,1,2,3,4,5] }},
      {numbers: { $in: [0,1,2,3,4,5]}}
    ]
  },
  populate: 'cover',
  select: 'cover name cont',
  limit: 10
};
db.get(_q,function(err,papers){
  if(err) done(true,err);
  else{
    done(null,papers);
  }
});

db.get as find

find all models.

var query = {
  model:'modelName'
};
db.get(query, callback(err, res){
  // do something
});

db.get as findById

modelID String

var query = {
  model:'modelName',
  id: modelID
};
db.get(query, callback(err, res){
  // do something
});

db.get - Find by multiple ids.

id accepts an Array of values.

modelID Array or String

var query = {
  model:'modelName',
  where: { _id : { $in : [...] } }
};
db.get(query, callback(err, res){
  // do something
});

db.get as find (passing a where option.)

var query = {
  model:'modelName',
  where: { ... } // list of columns
};
db.get(query, callback(err, res){
  // do something
});

db.create

var _q = {
  model:'Papers',
  body: { 
    name:'Important paper.',
    cont:'...'
  }
};
db.get(_q, callback(err, res){
  // do something
});

db.update (it's like using get.)

var _q={
  model: 'Papers',
  where: { name: 'Unnamed paper.' },
  body:{
    name: 'Important paper.'
  },
  limit: 10
};
db.update(_q,function(err,affected){
  done(err,affected);
});

db.update

passing a function

var _q={
  model: 'Papers',
  where: { _id: _id },
  body:function(model,opts,cb){
    // model - the model.
    // opts - this same _q object.
    // cb - callback for complete.
    // this - model schema.
    model.update({
      // update 1
    },{
      // update 2
    });
  }
};
db.update(_q,function(err,affected){
  done(err,affected);
});

db.destroy (it's like using get.)

var query = {
  model: 'modelName',
  where: { _id: _id }
};
db.destroy(query, callback(err, res){
  // do something
});

License (MIT)

Copyright (c) 2014 Victor P.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.