{"id":20170231,"url":"https://github.com/fabrix-app/spool-mongoose","last_synced_at":"2026-04-16T03:32:06.701Z","repository":{"id":95882837,"uuid":"173210959","full_name":"fabrix-app/spool-mongoose","owner":"fabrix-app","description":"Spool: Mongoose for Fabrix","archived":false,"fork":false,"pushed_at":"2019-03-01T01:08:32.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-03T14:42:45.643Z","etag":null,"topics":["fabrix","mongo","mongoose","spool"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabrix-app.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-01T00:57:30.000Z","updated_at":"2019-03-01T15:07:19.000Z","dependencies_parsed_at":"2023-08-31T21:47:37.737Z","dependency_job_id":null,"html_url":"https://github.com/fabrix-app/spool-mongoose","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fabrix-app/spool-mongoose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-mongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-mongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-mongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-mongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabrix-app","download_url":"https://codeload.github.com/fabrix-app/spool-mongoose/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabrix-app%2Fspool-mongoose/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31870506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"online","status_checked_at":"2026-04-16T02:00:06.042Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fabrix","mongo","mongoose","spool"],"created_at":"2024-11-14T01:17:47.004Z","updated_at":"2026-04-16T03:32:06.673Z","avatar_url":"https://github.com/fabrix-app.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spool-mongoose\n:package: Mongoose.js Spool [http://mongoosejs.com](http://mongoosejs.com)\n\n[![Gitter][gitter-image]][gitter-url]\n[![NPM version][npm-image]][npm-url]\n[![Build Status][ci-image]][ci-url]\n[![Test Coverage][coverage-image]][coverage-url]\n[![Dependency Status][daviddm-image]][daviddm-url]\n[![Follow @FabrixApp on Twitter][twitter-image]][twitter-url]\n\nLoads Application Models (in `api/models`) into the Mongoose ORM; Integrates with [spool-router](https://github.com/fabrix-app/spool-router) to\ngenerate Tapestriess for routes.\n\n## Usage\n\n### Include spool in app.\n\n```js\n// config/main.js\nmodule.exports = {\n  // ...\n  packs: [\n    require('spool-mongoose')\n  ]\n}\n```\n\n### Configure stores.\n\n```js\n// config/stores.ts\nexport const stores = {\n\n  /**\n   * Define the database stores. A store is typically a single database.\n   *\n   * Use the SQLite3 by default for development purposes.\n   *\n   * Set production connection info in config/env/production.js\n   */\n  someteststore: {\n    // migration\n    migrate: 'create',\n    // Mongodb URI\n    uri: 'mongodb://localhost:27017/test',\n    // Mongoose connection options\n    options: {\n\n    },\n    // Set this stores orm to mongoose\n    orm: 'mongoose'\n  }\n}\n\n// config/models.ts\nexport const models = {\n  defaultStore: 'someteststore',\n  migrate: 'drop'\n}\n\n```\n\n### Models\n\n#### Options\n\n##### Model::Schema\n\nSee [Mongoose Documentation for Schemas](http://mongoosejs.com/docs/guide.html).\n\n##### Model::Config\n\n| Option | Type | Default | Description |\n| --- | --- | --- | --- |\n| tableName | String | `modelName.toLowerCase()` | Name of collection to use with this model. For example: MyModel.js defaults to collection named `mymodel`\n| store | String | `app.config.database.models.defaultStore` | Datastore to use for this model; specify the name of one of the stores in `app.config.database.stores`.\n| migrate | String | | Migrate *must* be set to one of `[ 'none', 'drop', 'create' ]`\n| schema | Object | `{}` | [Schema Options](http://mongoosejs.com/docs/guide.html#options) to pass into Mongoose's Schema constructor.\n| statics | Object | `{}` | [Static methods](http://mongoosejs.com/docs/guide.html#statics) to add to the Model.\n| methods | Object | `{}` | [Instance methods](http://mongoosejs.com/docs/guide.html#methods) to add to this model's documents.\n| onSchema | Function | undefined | Funcion which is useful to for adding schema middleware, virtuals, or indexes.\n\n#### Example\n\n```js\n// Use default Schema from Mongoose. See http://mongoosejs.com/docs/schematypes.html\nmodule.exports = class User extends Model {\n\n  static schema (app, Mongoose) {\n    return {\n      username: String,\n      childs: [{\n        type: Mongoose.Schema.ObjectId,\n        ref: 'UserSchema'\n      }],\n      email: {\n        type: String,\n        required: true,\n        unique: true,\n        lowercase: true,\n        trim: true,\n        validate: {\n          validator: function (val) {\n            return isEmail(val)\n          },\n          message: '{VALUE} is not a valid email'\n        }\n      }\n    }\n  }\n\n  static config (app, Mongoose) {\n    return {\n      // Collection name\n      tableName: 'users',\n\n      // Schema options\n      schema: {\n        timestamps: true,\n\n        versionKey: false,\n\n        toObject: {\n          virtuals: true\n        },\n\n        toJSON: {\n          virtuals: true\n        }\n      },\n      // Schema statics\n      statics: {\n        getByEmail: function (email) {\n          return this\n            .findOne({\n              email: _.trim(email)\n            })\n            .exec()\n        },\n      },\n\n      // Schema methods\n      methods: {\n        toJSON: function () {\n          const user = this.toObject()\n          delete user.password\n\n          return user\n        }\n      },\n      \n      /**\n        * After Fabrix.js will create model Schema you could add anything you want here\n        * @param  {FabrixApp} app FabrixJs app object\n        * @param  {mongoose.Schema} schema mongoose new Schema object\n      */\n      onSchema (app, schema) {\n          // virtuals\n          schema.virtual('name.full').get(function () {\n            return this.name.first + ' ' + this.name.last\n          })\n          // lifecircle events\n          schema.pre('save', function (next) {\n            // performing actions\n            next()\n          })\n          \n          // text indexes\n          schema.index(\n            { \n              username: 'text',\n              email: 'text'\n            },\n            { \n              weights : {\n                username : 10,\n                email: 5\n              },\n              name: \"usersIndex\"\n            }\n          )\n        }\n    }\n  }\n}\n```\n\n### Query\n\n```js\n// api/services/UserService.js\nmodule.exports = class UserService extends Service {\n  /**\n   * Finds people with the given email.\n   * @return Promise\n   * @example {\n   *    name: 'Ludwig Beethoven',\n   *    email: 'someemail@email.com',\n   *    favoriteColors: [\n   *      { name: 'yellow', hex: 'ffff00' },\n   *      { name: 'black', hex: '000000' }\n   *     ]\n   * }\n   */\n  findUser (email) {\n    return this.orm.User.find({ email: email })\n      .exec()\n  }\n}\n```\n\n\n## Contributing\nWe love contributions! Please check out our [Contributor's Guide](https://github.com/fabrix-app/fabrix/blob/master/CONTRIBUTING.md) for more\ninformation on how our projects are organized and how to get started.\n\n\n## License\n[MIT](https://github.com/fabrix-app/spool-mongoose/blob/master/LICENSE)\n\n## Changelog\n[Changelog](https://github.com/fabrix-app/spool-mongoose/blob/master/CHANGELOG.md)\n\n[npm-image]: https://img.shields.io/npm/v/@fabrix/spool-mongoose.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@fabrix/spool-mongoose\n[ci-image]: https://img.shields.io/circleci/project/github/fabrix-app/spool-mongoose/master.svg\n[ci-url]: https://circleci.com/gh/fabrix-app/spool-mongoose/tree/master\n[daviddm-image]: http://img.shields.io/david/fabrix-app/spool-mongoose.svg?style=flat-square\n[daviddm-url]: https://david-dm.org/fabrix-app/spool-mongoose\n[gitter-image]: http://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square\n[gitter-url]: https://gitter.im/fabrix-app/Lobby\n[twitter-image]: https://img.shields.io/twitter/follow/FabrixApp.svg?style=social\n[twitter-url]: https://twitter.com/FabrixApp\n[coverage-image]: https://img.shields.io/codeclimate/coverage/github/fabrix-app/spool-mongoose.svg?style=flat-square\n[coverage-url]: https://codeclimate.com/github/fabrix-app/spool-mongoose/coverage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabrix-app%2Fspool-mongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabrix-app%2Fspool-mongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabrix-app%2Fspool-mongoose/lists"}