You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
492 B

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