Socket
Book a DemoInstallSign in
Socket

mpill

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mpill

MoNoApps MongoDB Pill

0.5.1
latest
Source
npmnpm
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

MPill

Coding apps without to be worried about data models.

Single model instance

var MPill = require('mpill').MPill;
var url = 'mongodb://127.0.0.1/mpill';
users = new MPill('users', url);

Multiple models at once

models.js

var MPill = require('../mpill.js').MPill;

var colls = ['users','groups','roles','tasks'];
var url   = 'mongodb://127.0.0.1/mydb';

// exports each collection
for(var i in colls){
	module.exports[colls[i]] = new MPill(colls[i], url);
}

userController.js (let's said this is for express route)

var models = require('./models');
var Users = {};

Users.List = function(req, res){
  models.users.FindOne({'email': 'rrunner@acme.co'}, function(err, rrunner){
    if(err){ return res.status(500); }
    var query = { user_id: rrunner._id, label: 'open' };
      models.tasks.Find(query, function(err, toDo){
        if(err){ return res.status(500); }
        res.json({
          user: rrunner,
          tasks: toDo
        });
      });
    });
};
...
module.exports.Users = Users;

API reference

'Generic methods'
model.Connect(cb)
model.DropDB(cb)

'Common methods'
model.Insert(doc, cb)
model.Update(query, doc, concern, cb)
model.Remove(query, cb)
model.Find(query, cb, project, options, limit, sort)
model.FindOne(query, cb)
model.CreateIndex(query, cb)
model.DropCollection(query, cb)
model.DropIndex(query, cb)
model.CreateCollection(cb)
model.Count(query, cb)
model.Aggregate(query, cb)

'Special methods'
model.FindByObjectId(query, key, cb)
model.UpdateByObjectId(query, doc, key, cb)
model.RemoveByObjectId(query, key, cb)
model.parseOID(value, cb)

Test with tpill

Running CRUD sample

npm install
// mongod --dbpath $HOME/data/mpill &
node example/crud.js

Results:

✓ CreateCollection
✓ DropCollection
✓ Insert
✓ Update
✓ FindOne
✓ FindByObjectId
✓ UpdateByObjectId
✓ RemoveByObjectId
✓ Count
✓ DropDB

Statistics: {"pass":10,"fail":0,"warn":0}

RESTful API sample

Clone deck tool to see a restify implementation.

Test with mocha

Keeps definded functions.

mocha
18 passing (20ms)

Code quality with gulp-jshint

npm install gulp
npm install gulp-jshint
gulp

About concern

Full api doc: http://docs.mongodb.org/manual/reference/write-concern/

//Sample with concern
var concern = {w:1}; //Use primary node server

Changelog:

v0.5.1

  • Add Aggregation framework queries.
  • Add tests for mongo v3

v0.5.0

  • Stable version for common queries

Keywords

mongo

FAQs

Package last updated on 12 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.