{"id":13487536,"url":"https://github.com/eggjs/egg-mongoose","last_synced_at":"2025-05-15T21:04:24.080Z","repository":{"id":17463463,"uuid":"82033770","full_name":"eggjs/egg-mongoose","owner":"eggjs","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-08T05:34:44.000Z","size":58,"stargazers_count":442,"open_issues_count":11,"forks_count":103,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-05T06:40:18.756Z","etag":null,"topics":["egg","egg-plugin","mongodb","mongodb-orm","mongoose"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/eggjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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":"2017-02-15T07:44:24.000Z","updated_at":"2025-04-18T15:53:11.000Z","dependencies_parsed_at":"2023-12-22T11:06:46.193Z","dependency_job_id":"7303287e-7aaf-4448-8cf0-c641b3ae0d11","html_url":"https://github.com/eggjs/egg-mongoose","commit_stats":{"total_commits":45,"total_committers":22,"mean_commits":"2.0454545454545454","dds":0.8222222222222222,"last_synced_commit":"6586f7d951d9df1a072eea4a1f2242347281261e"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-mongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-mongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-mongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-mongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-mongoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253365316,"owners_count":21897181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["egg","egg-plugin","mongodb","mongodb-orm","mongoose"],"created_at":"2024-07-31T18:01:00.399Z","updated_at":"2025-05-15T21:04:24.058Z","avatar_url":"https://github.com/eggjs.png","language":"JavaScript","funding_links":[],"categories":["Plugins","仓库"],"sub_categories":["插件"],"readme":"# egg-mongoose\n\n[![NPM version][npm-image]][npm-url]\n[![Run tests](https://github.com/eggjs/egg-mongoose/actions/workflows/autoUnitTest.yml/badge.svg)](https://github.com/eggjs/egg-mongoose/actions/workflows/autoUnitTest.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-mongoose.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-mongoose\n[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-mongoose.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/eggjs/egg-mongoose?branch=master\n[snyk-image]: https://snyk.io/test/npm/egg-mongoose/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-mongoose\n[download-image]: https://img.shields.io/npm/dm/egg-mongoose.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-mongoose\n\nEgg's mongoose plugin.\n\n## Install\n\n```bash\nnpm i egg-mongoose --save\n```\n\n## Configuration\n\nChange `{app_root}/config/plugin.js` to enable `egg-mongoose` plugin:\n\n```js\nexports.mongoose = {\n  enable: true,\n  package: 'egg-mongoose',\n};\n```\n\n## Simple connection\n\n### Config\n\n```js\n// {app_root}/config/config.default.js\nexports.mongoose = {\n  url: 'mongodb://127.0.0.1/example',\n  options: {},\n  // mongoose global plugins, expected a function or an array of function and options\n  plugins: [createdPlugin, [updatedPlugin, pluginOptions]],\n};\n// recommended\nexports.mongoose = {\n  client: {\n    url: 'mongodb://127.0.0.1/example',\n    options: {},\n    // mongoose global plugins, expected a function or an array of function and options\n    plugins: [createdPlugin, [updatedPlugin, pluginOptions]],\n  },\n};\n```\n\n### Example\n\n```js\n// {app_root}/app/model/user.js\nmodule.exports = app =\u003e {\n  const mongoose = app.mongoose;\n  const Schema = mongoose.Schema;\n\n  const UserSchema = new Schema({\n    userName: { type: String  },\n    password: { type: String  },\n  });\n\n  return mongoose.model('User', UserSchema);\n}\n\n// {app_root}/app/controller/user.js\nexports.index = function* (ctx) {\n  ctx.body = yield ctx.model.User.find({});\n}\n```\n\n## Multiple connections\n\n### Config\n\n```js\n// {app_root}/config/config.default.js\nexports.mongoose = {\n  clients: {\n    // clientId, access the client instance by app.mongooseDB.get('clientId')\n    db1: {\n      url: 'mongodb://127.0.0.1/example1',\n      options: {},\n      // client scope plugin array\n      plugins: []\n    },\n    db2: {\n      url: 'mongodb://127.0.0.1/example2',\n      options: {},\n    },\n  },\n  // public scope plugin array\n  plugins: []\n};\n```\n\n### Example\n\n```js\n// {app_root}/app/model/user.js\nmodule.exports = app =\u003e {\n  const mongoose = app.mongoose;\n  const Schema = mongoose.Schema;\n  const conn = app.mongooseDB.get('db1'); \n\n  const UserSchema = new Schema({\n    userName: { type: String },\n    password: { type: String },\n  });\n\n  return conn.model('User', UserSchema);\n}\n\n// {app_root}/app/model/book.js\nmodule.exports = app =\u003e {\n  const mongoose = app.mongoose;\n  const Schema = mongoose.Schema;\n  const conn = app.mongooseDB.get('db2');\n\n  const BookSchema = new Schema({\n    name: { type: String },\n  });\n\n  return conn.model('Book', BookSchema);\n}\n\n// app/controller/user.js\nexports.index = function* (ctx) {\n  ctx.body = yield ctx.model.User.find({}); // get data from db1\n}\n\n// app/controller/book.js\nexports.index = function* (ctx) {\n  ctx.body = yield ctx.model.Book.find({}); // get data from db2\n}\n```\n\n### Default config\n\nsee [config/config.default.js](config/config.default.js) for more detail.\n\n## Multi-mongos support\n\n```js\n// {app_root}/config/config.default.js\nexports.mongoose = {\n  client: {\n    url: 'mongodb://mongosA:27501,mongosB:27501',\n    options: {\n      mongos: true,\n    },\n  },\n};\n```\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg-mongoose/issues).\n\n## Contribution\n\nIf you are a contributor, follow [CONTRIBUTING](https://eggjs.org/zh-cn/contributing.html).\n\n## License\n\n[MIT](LICENSE)\n\n\u003c!-- GITCONTRIBUTOR_START --\u003e\n\n## Contributors\n\n|[\u003cimg src=\"https://avatars.githubusercontent.com/u/893152?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ejtyjty99999\u003c/b\u003e\u003c/sub\u003e](https://github.com/jtyjty99999)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/360661?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003epopomore\u003c/b\u003e\u003c/sub\u003e](https://github.com/popomore)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/227713?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eatian25\u003c/b\u003e\u003c/sub\u003e](https://github.com/atian25)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/985607?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003edead-horse\u003c/b\u003e\u003c/sub\u003e](https://github.com/dead-horse)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/17738556?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eBaffinLee\u003c/b\u003e\u003c/sub\u003e](https://github.com/BaffinLee)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/13268073?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003etrylovetom\u003c/b\u003e\u003c/sub\u003e](https://github.com/trylovetom)\u003cbr/\u003e|\n| :---: | :---: | :---: | :---: | :---: | :---: |\n|[\u003cimg src=\"https://avatars.githubusercontent.com/u/9605663?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eChangedenCZD\u003c/b\u003e\u003c/sub\u003e](https://github.com/ChangedenCZD)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/954064?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ehardywu\u003c/b\u003e\u003c/sub\u003e](https://github.com/hardywu)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/7105264?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eJasinYip\u003c/b\u003e\u003c/sub\u003e](https://github.com/JasinYip)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/549979?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003enetputer\u003c/b\u003e\u003c/sub\u003e](https://github.com/netputer)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/52018749?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eWai-Dung\u003c/b\u003e\u003c/sub\u003e](https://github.com/Wai-Dung)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/7284558?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eduncup\u003c/b\u003e\u003c/sub\u003e](https://github.com/duncup)\u003cbr/\u003e|\n[\u003cimg src=\"https://avatars.githubusercontent.com/u/5010606?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ejinasonlin\u003c/b\u003e\u003c/sub\u003e](https://github.com/jinasonlin)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/8500303?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003elegendecas\u003c/b\u003e\u003c/sub\u003e](https://github.com/legendecas)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/20775828?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003elzqmyb\u003c/b\u003e\u003c/sub\u003e](https://github.com/lzqmyb)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/70498637?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eDevXiaolan\u003c/b\u003e\u003c/sub\u003e](https://github.com/DevXiaolan)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/1774223?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003evillins\u003c/b\u003e\u003c/sub\u003e](https://github.com/villins)\u003cbr/\u003e\n\nThis project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sat Aug 12 2023 11:16:17 GMT+0800`.\n\n\u003c!-- GITCONTRIBUTOR_END --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-mongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-mongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-mongoose/lists"}