arnaucube
arnaucube/thoughtsPublic Self-hosted repository
thoughts/node_modules/mongoose/examples/statics/person.js
node_modules/mongoose/examples/statics/person.jsRaw
 1// import the necessary modules
 2var mongoose = require('../../lib');
 3var Schema = mongoose.Schema;
 4
 5// create an export function to encapsulate the model creation
 6module.exports = function() {
 7  // define schema
 8  var PersonSchema = new Schema({
 9    name: String,
10    age: Number,
11    birthday: Date
12  });
13
14  // define a static
15  PersonSchema.statics.findPersonByName = function(name, cb) {
16    this.find({name: new RegExp(name, 'i')}, cb);
17  };
18
19  mongoose.model('Person', PersonSchema);
20};