{"id":13487546,"url":"https://github.com/brickyang/egg-mongo-native","last_synced_at":"2025-04-16T20:53:21.468Z","repository":{"id":57220591,"uuid":"95995394","full_name":"brickyang/egg-mongo-native","owner":"brickyang","description":"MongoDB egg.js plugin using native driver.","archived":false,"fork":false,"pushed_at":"2019-09-21T06:52:01.000Z","size":160,"stargazers_count":75,"open_issues_count":2,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T08:46:34.573Z","etag":null,"topics":["egg-plugin","eggjs","mongodb","mongodb-driver"],"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/brickyang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-02T01:11:05.000Z","updated_at":"2023-03-13T12:17:25.000Z","dependencies_parsed_at":"2022-08-29T00:11:57.023Z","dependency_job_id":null,"html_url":"https://github.com/brickyang/egg-mongo-native","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brickyang%2Fegg-mongo-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brickyang%2Fegg-mongo-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brickyang%2Fegg-mongo-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brickyang%2Fegg-mongo-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brickyang","download_url":"https://codeload.github.com/brickyang/egg-mongo-native/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249275775,"owners_count":21242284,"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-plugin","eggjs","mongodb","mongodb-driver"],"created_at":"2024-07-31T18:01:00.489Z","updated_at":"2025-04-16T20:53:21.449Z","avatar_url":"https://github.com/brickyang.png","language":"JavaScript","readme":"[![NPM version][npm-image]][npm-url]\n[![NPM quality][quality-image]][quality-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-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-mongo-native.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-mongo-native\n[quality-image]: http://npm.packagequality.com/shield/egg-mongo-native.svg?style=flat-square\n[quality-url]: http://packagequality.com/#?package=egg-mongo-native\n[travis-image]: https://img.shields.io/travis/brickyang/egg-mongo-native.svg?branch=master\u0026style=flat-square\n[travis-url]: https://travis-ci.org/brickyang/egg-mongo-native\n[codecov-image]: https://img.shields.io/codecov/c/github/brickyang/egg-mongo-native.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/brickyang/egg-mongo-native?branch=master\n[david-image]: https://img.shields.io/david/brickyang/egg-mongo-native.svg?branch=master\u0026style=flat-square\n[david-url]: https://david-dm.org/brickyang/egg-mongo-native?branch=master\n[snyk-image]: https://snyk.io/test/npm/egg-mongo-native/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-mongo-native\n[download-image]: https://img.shields.io/npm/dm/egg-mongo-native.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-mongo-native\n\n[**中文版**](https://github.com/brickyang/egg-mongo/blob/master/README.zh_CN.md)\n\nUsers who don't use Egg.js could use [easy-mongodb](https://github.com/brickyang/easy-mongodb).\n\nThis plugin base on\n[node-mongodb-native](https://github.com/mongodb/node-mongodb-native), provides\nthe official MongoDB native driver and APIs.\n\nIt wraps some frequently-used API to make it easy to use but keep all properties\nas it is. For example, to find a document you need this with official API\n\n```js\ndb.collection('name')\n  .find(query, options)\n  .skip(skip)\n  .limit(limit)\n  .project(project)\n  .sort(sort)\n  .toArray();\n```\n\nand with this plugin\n\n```js\napp.mongo.find('name', { query, skip, limit, project, sort, options });\n```\n\n## Install\n\n```bash\n$ npm i egg-mongo-native --save\n```\n\n## Enable Plugin\n\n```js\n// {app_root}/config/plugin.js\nexports.mongo = {\n  enable: true,\n  package: 'egg-mongo-native',\n};\n```\n\n## Configuration\n\n### Single Instance\n\n```js\n// {app_root}/config/config.default.js\nexports.mongo = {\n  client: {\n    host: 'host',\n    port: 'port',\n    name: 'test',\n    user: 'user',\n    password: 'password',\n    options: {},\n  },\n};\n```\n\n### Replica Set (v2.1.0 or higher)\n\n```js\n// mongodb://host1:port1,host2:port2/name?replicaSet=test\nexports.mongo = {\n  client: {\n    host: 'host1,host2',\n    port: 'port1,port2',\n    name: 'name',\n    options: {\n      replicaSet: 'test',\n    },\n  },\n};\n\n// mongodb://host:port1,host:port2/name?replicaSet=test\nexports.mongo = {\n  client: {\n    host: 'host', // or ['host']\n    port: 'port1,port2', // or ['port1', 'port2']\n    name: 'name',\n    options: {\n      replicaSet: 'test',\n    },\n  },\n};\n```\n\n### Multiple Instances\n\n\u003e **Can not set `client` and `clients` both.**\n\n```js\n// {app_root}/config/config.default.js\nexports.mongo = {\n  clients: {\n    db1: {\n      host: 'host',\n      port: 'port',\n      name: 'db1',\n      user: 'user',\n      password: 'password',\n      options: {},\n    },\n    db2: {\n      host: 'host',\n      port: 'port',\n      name: 'db2',\n      user: 'user',\n      password: 'password',\n      options: {},\n    },\n  },\n};\n```\n\nsee [config/config.default.js](config/config.default.js) for more detail.\n\n## Example\n\nThe APIs provided by plugin usually need two arguments. The first is commonly\nthe collection name, and the second is an object keeps the arguments of official\nAPI. For example, to insert one document using official API\n\n```js\ndb.collection('name').insertOne(doc, options);\n```\n\nand using plugin API\n\n```js\nconst args = { doc, options };\napp.mongo.insertOne('name', args);\n```\n\n**For Multiple Instances**\n\n```js\nconst args = { doc, options };\napp.mongo.get('db1').insertOne('name', args);\n```\n\nThe `args` is an object provides the arguments to official API.\n\nPlease read [easy-mongodb](https://github.com/brickyang/easy-mongodb) for all APIs(tansaction is now supported) and more examples.\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":["Plugins","仓库"],"sub_categories":["插件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrickyang%2Fegg-mongo-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrickyang%2Fegg-mongo-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrickyang%2Fegg-mongo-native/lists"}