mongoose-wrappers
v0.0.1
Published
Wrappers around the Mongoose library that aims to simplify the way Schemas and Models are defined.
Downloads
6
Maintainers
Readme
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 }
]
});