trailpack-mongoose
📦 Mongoose.js Trailpack http://mongoosejs.com
Loads Application Models (in api/models
) into the Mongoose ORM; Integrates with trailpack-router to
generate Footprints for routes.
Usage
Configure
// config/main.jsmoduleexports = // ... packs:
Configure stores
// config/database.jsmoduleexports = /** * Define the database stores. A store is typically a single database. * * Use the SQLite3 by default for development purposes. * * Set production connection info in config/env/production.js */ stores: /** * Define a store called "local" which uses SQLite3 to persist data. */ someteststore: //migration migrate: 'create' // Mongodb URI uri: 'mongodb://localhost:27017/test' // Mongoose connection options options: models: defaultStore: 'someteststore' migrate: 'drop'
Models
// Use default Schema from Mongoose. See http://mongoosejs.com/docs/schematypes.htmlmoduleexports = static { return username: String childs: type: MongooseSchemaObjectId ref: 'UserSchema' email: type: String required: true unique: true lowercase: true trim: true validate: { return } message: '{VALUE} is not a valid email' } static { return // Collection name tableName: 'users' // Schema options schema: timestamps: true versionKey: false toObject: virtuals: true toJSON: virtuals: true // Schema statics statics: { return this } // Schema methods methods: { const user = this delete userpassword return user } /** * After Trails.js will create model Schema you could add anything you want here * @param * @param */ { // virtuals schema // lifecircle events schema } }``` ### Query ```js// api/services/UserService.jsmoduleexports = /** * Finds people with the given email. * @return Promise * @example { * name: 'Ludwig Beethoven', * email: 'someemail@email.com', * favoriteColors: [ * { name: 'yellow', hex: 'ffff00' }, * { name: 'black', hex: '000000' } * ] * } */ { return thisormUser }
Contributing
We love contributions! Please check out our Contributor's Guide for more information on how our projects are organized and how to get started.