1.0.9 • Published 9 years ago

xx-mongoose v1.0.9

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

Usage

Define your models, for example

App.models.project = {
  mongooseSchema: {
    name: { type: String },
    date: { type: Date, default: Date.now, private: true }
  },
  //this will be called before registering the Schema
  mongoosePremodel: function(Schema) {
    Schema.path('name').set(function(v) {
      return v.toUpperCase();
    });
    Schema.pre('save').set(function(next) {
      // do something
      next();
    });
  }
  instanceMethod: {
    doSomething: function() {}
  }
};

When you're done defining them, add App.load('mongoose/model'); to your app.js. If you pass an additional string, for example App.load('mongoose/model', 'mongodb://localhost/my_database);, mongoose will connect to that database. Otherwise it will connect to the database defined in App.configuration.mongoose.url

Every method from instanceMethods will be added as instance methods to the schema.

In addition to mongoose, you can define private on attributes. This will hide these attributes when callig toJSON. Useful for sensitive information

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago