mongoose-wrappers

0.0.1 • Public • Published

Mongoose Wrappers

Wrappers around the Mongoose library that aims to simplify the way Schemas and Models are defined.

Schemas

Schemas can be defined with a single object literal.

var Schema = require('mongoose-wrappers').Schema;
 
var AnimalSchema = new Schema({
  paths: {
    name: { type: 'String' },
    type: { type: 'String' }
  },
  virtuals: {
    title: {
      get: function() {
        return this.name + '' + this.type;
      }
    }
  }, 
  methods: {
    findSimilarTypes: function(cb) {
      return this.model('Animal').find({ type: this.type }, cb);
    }
  },
  statics: {
    findByName: function(name, cb) {
      this.find({ name: new RegExp(name, 'i') }, cb);
    }
  },
  indexes: [
    { name: 1, type: -1 }
  ]
});

Package Sidebar

Install

npm i mongoose-wrappers

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • noisypebble