{"id":18862195,"url":"https://github.com/hapinessjs/mongo-module","last_synced_at":"2025-08-21T11:14:19.187Z","repository":{"id":47331031,"uuid":"94753163","full_name":"hapinessjs/mongo-module","owner":"hapinessjs","description":"MongoDB module for Hapiness framework","archived":false,"fork":false,"pushed_at":"2023-03-02T11:43:08.000Z","size":1275,"stargazers_count":0,"open_issues_count":13,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-08-08T17:16:51.372Z","etag":null,"topics":[],"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/hapinessjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-06-19T08:18:25.000Z","updated_at":"2021-03-30T17:02:19.000Z","dependencies_parsed_at":"2024-11-08T04:44:26.086Z","dependency_job_id":null,"html_url":"https://github.com/hapinessjs/mongo-module","commit_stats":{"total_commits":108,"total_committers":8,"mean_commits":13.5,"dds":0.6851851851851851,"last_synced_commit":"482b8b47430816530edda119a18b43f029f53caa"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/hapinessjs/mongo-module","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapinessjs%2Fmongo-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapinessjs%2Fmongo-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapinessjs%2Fmongo-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapinessjs%2Fmongo-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hapinessjs","download_url":"https://codeload.github.com/hapinessjs/mongo-module/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapinessjs%2Fmongo-module/sbom","scorecard":{"id":455201,"data":{"date":"2025-08-11","repo":{"name":"github.com/hapinessjs/mongo-module","commit":"482b8b47430816530edda119a18b43f029f53caa"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Code-Review","score":5,"reason":"Found 8/16 approved changesets -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"83 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-mg85-8mv5-ffjr","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-4jwp-vfvf-657p","Warn: Project is vulnerable to: GHSA-v8w9-2789-6hhr","Warn: Project is vulnerable to: GHSA-h452-7996-h45h","Warn: Project is vulnerable to: GHSA-897m-rjf5-jp39","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-rq8g-5pc5-wrhr","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-7hx8-2rxv-66xv","Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-8687-vv9j-hgph","Warn: Project is vulnerable to: GHSA-f825-f98c-gj3g","Warn: Project is vulnerable to: GHSA-h8hf-x3f4-xwgp","Warn: Project is vulnerable to: GHSA-9m93-w8w6-76hh","Warn: Project is vulnerable to: GHSA-m7xq-9374-9rvx","Warn: Project is vulnerable to: GHSA-vg7j-7cwx-8wgw","Warn: Project is vulnerable to: GHSA-p92x-r36w-9395","Warn: Project is vulnerable to: GHSA-45q2-34rf-mr94","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-2mvq-xp48-4c77","Warn: Project is vulnerable to: GHSA-5854-jvxx-2cg9","Warn: Project is vulnerable to: GHSA-g64q-3vg8-8f93","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp","Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2","Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6","Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-wrvr-8mpx-r7pp","Warn: Project is vulnerable to: GHSA-mh5c-679w-hh4r","Warn: Project is vulnerable to: GHSA-h466-j336-74wx","Warn: Project is vulnerable to: GHSA-gqgv-6jq5-jjj9","Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7","Warn: Project is vulnerable to: GHSA-8225-6cvr-8pqp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T09:23:42.456Z","repository_id":47331031,"created_at":"2025-08-19T09:23:42.456Z","updated_at":"2025-08-19T09:23:42.456Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271469223,"owners_count":24765124,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"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":[],"created_at":"2024-11-08T04:33:37.461Z","updated_at":"2025-08-21T11:14:19.162Z","avatar_url":"https://github.com/hapinessjs.png","language":"TypeScript","readme":"\u003cimg src=\"http://bit.ly/2mxmKKI\" width=\"500\" alt=\"Hapiness\" /\u003e\n\n\u003cdiv style=\"margin-bottom:20px;\"\u003e\n\u003cdiv style=\"line-height:60px\"\u003e\n    \u003ca href=\"https://travis-ci.org/hapinessjs/mongo-module.svg?branch=master\"\u003e\n        \u003cimg src=\"https://travis-ci.org/hapinessjs/mongo-module.svg?branch=master\" alt=\"build\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://coveralls.io/github/hapinessjs/mongo-module?branch=master\"\u003e\n        \u003cimg src=\"https://coveralls.io/repos/github/hapinessjs/mongo-module/badge.svg?branch=master\" alt=\"coveralls\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://david-dm.org/hapinessjs/mongo-module\"\u003e\n        \u003cimg src=\"https://david-dm.org/hapinessjs/mongo-module.svg\" alt=\"dependencies\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://david-dm.org/hapinessjs/mongo-module?type=dev\"\u003e\n        \u003cimg src=\"https://david-dm.org/hapinessjs/mongo-module/dev-status.svg\" alt=\"devDependencies\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n    \u003ca href=\"https://www.typescriptlang.org/docs/tutorial.html\"\u003e\n        \u003cimg src=\"https://cdn-images-1.medium.com/max/800/1*8lKzkDJVWuVbqumysxMRYw.png\"\n             align=\"right\" alt=\"Typescript logo\" width=\"50\" height=\"50\" style=\"border:none;\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://reactivex.io/rxjs\"\u003e\n        \u003cimg src=\"http://reactivex.io/assets/Rx_Logo_S.png\"\n             align=\"right\" alt=\"ReactiveX logo\" width=\"50\" height=\"50\" style=\"border:none;\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://hapijs.com\"\u003e\n        \u003cimg src=\"http://bit.ly/2lYPYPw\"\n             align=\"right\" alt=\"Hapijs logo\" width=\"75\" style=\"border:none;\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n# Mongo Module\n\n`Mongo` module for the Hapiness framework including `mongoose`, `mongoose-gridfs` (deprecated) and `mongoose-gridfs-bucket` adapter one.\n\n## Table of contents\n\n* [Using your module inside Hapiness application](#using-your-module-inside-hapiness-application)\n    * [`yarn` or `npm` it in your `package.json`](#yarn-or-npm-it-in-your-package)\n    * [Importing `MongoModule` from the library](#importing-mongomodule-from-the-library)\n* [Creating `Adapters`](#creating-adapters)\n    * [Step 1](step-1)\n    * [Step 2](step-2)\n    * [Step 3](step-3)\n* [Registering adapters](registering-adapters)\n* [Using a registered adapter](#using-a-registered-adapter)\n* [Configuration](#configuration)\n* [Get your adapter anywhere](#get-your-adapter-anywhere)\n* [Model management](#model-management)\n* [Helpers functions](#helpers-functions)\n* [Contributing](#contributing)\n* [Change History](#change-history)\n* [Maintainers](#maintainers)\n* [License](#license)\n\n## Using your module inside Hapiness application\n\n### `yarn` or `npm` it in your `package.json`\n\n```bash\n$ npm install --save @hapiness/core @hapiness/mongo rxjs\n\nor\n\n$ yarn add @hapiness/core @hapiness/mongo rxjs\n```\n\n```json5\n\"dependencies\": {\n    \"@hapiness/core\": \"^1.3.0\",\n    \"@hapiness/mongo\": \"^1.1.3\",\n    \"rxjs\": \"^5.5.6\",\n    //...\n}\n//...\n```\n\n### Importing `MongoModule` from the library\n\nThis module provide an Hapiness extension for Mongo. To use it, simply register it during the `bootstrap` step of your project like that:\n\n```typescript\nimport { MongoModule, MongoClientExt } from '@hapiness/mongo';\n\n@HapinessModule({\n    version: '1.0.0',\n    providers: [ ],\n    declarations: [ ],\n    imports: [ MongoModule ]\n})\nclass MyModule implements OnStart {\n\n    constructor() { /* ... */ }\n}\n\nHapiness.bootstrap(MyModule, [ MongoClientExt.setConfig(/* ... */) ]);\n```\n\n[Back to top](#table-of-contents)\n\n## Creating `Adapters`\n\nThe `Mongo` module is based on adapters. Included to the module, there is an adapter using mongoose and one using mongoose to manage gridfs.\n\nBut you can create your own adapters if you want by following some required steps described belows.\n\n### Step 1\n\nYour adapter should be a class which inherits from `AbstractHapinessMongoAdapter`.\n\n### Step 2\n\nYou absolutely need to implement a static function `getInterfaceName`, which will return a uniq string identifier for your adapter (**NOTE** `mongoose`, `mongoose-gridfs` and `mongoose-gridfs-bucket` are already used by adapters provided by this module).\n\n### Step 3\n\nYou need to override 4 functions\n\n```typescript\n    _tryConnect(): Observable\u003cvoid\u003e { /* ... */ }\n\n    _afterConnect(): Observable\u003cvoid\u003e { /* ... */ }\n\n    getLibrary(): any { /* ... */ }\n\n    registerValue(): any { /* ... */ }\n```\n\n*_tryConnect:* you will create your database connection inside\n\nExample for mongoose\n\n```typescript\nprotected _tryConnect(): Observable\u003cvoid\u003e {\n        return Observable\n            .create(observer =\u003e {\n                this._isReady = false;\n\n                if (this._db) {\n                    this._db.close();\n                }\n\n                const connectOptions = {\n                    server: {\n                        reconnectTries: Number.MAX_VALUE,\n                        reconnectInterval: 5000,\n                    },\n                };\n\n                this._connection = mongoose.createConnection(this._uri, connectOptions);\n\n                this._connection.once('connected', () =\u003e {\n                    observer.next();\n                    observer.complete();\n                });\n\n                this._connection.once('error', err =\u003e {\n                    observer.error(err);\n                });\n            });\n    }\n```\n\n*_afterConnect:* this function will be called just after `_tryConnect` if you want to manage some stuff once your connection is fine.\n\nExample for mongoose:\n\n```typescript\nprotected _afterConnect(): Observable\u003cvoid\u003e {\n        return Observable\n            .create(observer =\u003e {\n                this._db = this._connection.db;\n\n                this.onConnected().subscribe(_ =\u003e {\n                    /* ... */\n                }, (e) =\u003e {\n                    /* ... */\n                });\n\n                this._connection.once('error', err =\u003e\n                    this.onError(err).subscribe(_ =\u003e {\n                        /* ... */\n                    }, (e) =\u003e {\n                        /* ... */\n                    })\n                );\n\n                this._connection.once('disconnected', () =\u003e\n                    this.onDisconnected().subscribe(_ =\u003e {\n                        /* ... */\n                    }, (e) =\u003e {\n                        /* ... */\n                    })\n                );\n\n                observer.next();\n                observer.complete();\n            });\n    }\n```\n\n*getLibrary:* this will just return the library your adapter use to use it as you want.\n\nExample for mongoose:\n\n```typescript\npublic getLibrary(): any {\n    return mongoose;\n}\n```\n\n*registerValue:* this will register your document and return a model value to get through the DI.\n\nExample for mongoose:\n\n```typescript\npublic registerValue(document, collection): any {\n    return this._connection.model(collection, document);\n}\n```\n\n**NOTE** DONT FORGET TO SET `_isReady = true` once you are done, else your adapter will never be ready.\n\nYou should also override:\n\n```typescript\n    close(): Observalbe\u003cvoid\u003e { /*  */ }\n```\n\n[Back to top](#table-of-contents)\n\n## Registering adapters\n\nWhen you want to create your own adapters, first you need to tell the Mongo extension to register it. The Mongo extension will add your classes and map it with the uniq identifier you put inside the static `ddd`.\n\n```typescript\nclass MyCustomAdapter extends AbstractHapinessMongoAdapter {\n    public static getInterfaceName(): string {\n        return 'custom-identifier-for-my-adapter';\n    }\n\n    constructor(options) { super(options); }\n\n    /* ... */\n}\n\nHapiness.bootstrap(\n    MyModule,\n    [\n        MongoClientExt\n            .setConfig(\n                {\n                    register: [ MyCustomAdapter ]\n                }\n            )\n    ]\n);\n```\n\nNow, the mongo extension knows that an Adapter with the identifier `custom-identifier-for-my-adapter` exists.\n\nThe two provided adapters don't need to be registered as it is already done.\n\n## Using a registered adapter\n\nIt will work the same for both custom adapters you made and provided adapters.\n\nJust load them with the config you want to use:\n\n```typescript\nclass MyCustomAdapter extends AbstractHapinessMongoAdapter {\n    public static getInterfaceName(): string {\n        return 'custom-identifier-for-my-adapter';\n    }\n\n    constructor(options) { super(options); }\n}\n\nHapiness.bootstrap(\n    MyModule,\n    [\n        MongoClientExt\n            .setConfig(\n                {\n                    register: [ MyCustomAdapter ]\n                    load: [\n                        {\n                            name: 'custom-identifier-for-my-adapter',\n                            config: {\n                                host: 'my.hostname1.com',\n                                port: 27017,\n                                db: 'db_1'\n                            }\n                        },\n                        {\n                            name: 'mongoose',\n                            config: {\n                                host: 'my.hostname2.com',\n                                port: 27017,\n                                db: 'db_1'\n                            }\n                        }\n                    ]\n                }\n            )\n    ]\n);\n```\n\nSo you can load as many connections as you want and provide custom configs for each adapter you load.\n\n[Back to top](#table-of-contents)\n\n## Configuration\n\nWhen you load adapters (see previous section), you can provide a config, but you have the possibility to not provide one every time.\n\nLets say you want two adapters pointing to the same database, you can for that use the `common` option.\n\n```typescript\nclass MyCustomAdapter extends AbstractHapinessMongoAdapter {\n    public static getInterfaceName(): string {\n        return 'custom-identifier-for-my-adapter';\n    }\n\n    constructor(options) { super(options); }\n}\n\nHapiness.bootstrap(\n    MyModule,\n    [\n        MongoClientExt\n            .setConfig(\n                {\n                    register: [ MyCustomAdapter ]\n                    common: {\n                        host: 'my.hostname.com',\n                        port: 27017,\n                        db: 'my_db'\n                    }\n                    load: [\n                        {\n                            name: 'custom-identifier-for-my-adapter'\n                        },\n                        {\n                            name: 'mongoose'\n                        }\n                    ]\n                }\n            )\n    ]\n);\n```\n\n[Back to top](#table-of-contents)\n\n## Get your adapter anywhere\n\nTo get your adapter and play with it, you need to inject the MongoClientService in your class and call the `get()` function to get an instance of the adapter manager.\n\nOnce you did it, you'll be able to get your adapter with its name only or with its name and options (if you have the same adapter in different DBs or host ...) calling the function `getAdapter(...)`.\n\nExample showing how to get mongoose adapter for `my_database`:\n\n```typescript\n@Injectable()\nclass MyModelDocument {\n    private _myModelConnection: any;\n\n    constructor(\n        private _mongoClient: MongoClientService\n    ) {\n        this._myModelConnection = null;\n    }\n\n    init() {\n        // You can do that...\n        const dao = this._mongoClient.get().getAdapter('mongoose').getLibrary();\n\n        // ... or that\n        const connection = this._mongoClient.get().getAdapter('mongoose', { db: 'my_database' }).getConnection();\n\n        const MyModel = dao.Schema({\n            username: String,\n        });\n\n        this._myModelConnection = connection.model('MyModel', MyModel);\n    }\n\n    get() {\n        return this._myModelConnection;\n    }\n}\n```\n\n[Back to top](#table-of-contents)\n\n## Model Management\n\nYou can implement and register models in the adapter\n\nExample:\n\n```typescript\n@MongoModel({\n    adapter: 'mongoose',\n    collection: 'collection', // The name of the collection, will be pluralize using mongoose if no collectionName is explicitly given\n    collectionName: 'collectionName', // Optional, will force this name as the collection name\n    options: { ... } // @see HapinessMongoAdapterConstructorArgs type\n})\nclass MyModel extends Model {\n\n    readonly schema;\n\n    constructor(private mongoClientService: MongoClientService) {\n        super(MyModel) // /!\\ Important to get connection options\n        const DAO = mongoClientService.getDao(this.connectionOptions);\n        this.schema = new DAO.Schema({\n            id: String\n        });\n\n        ...\n    }\n}\n\n@Route({\n    path: '/my-route',\n    method: 'get'\n})\nclass MyRoute implements OnGet {\n    constructor(private mongoClientService: MongoClientService) {}\n\n    onGet(request, reply) {\n        const model = this.mongoClientService.getModel({ adapter: 'mongoose', options: {} }, MyModel);\n\n        ...\n    }\n}\n\n@HapinessModule({\n    version: '1.0.0',\n    declarations: [ MyModel, MyRoute ]\n})\nclass MyModule {}\n\n```\n\n[Back to top](#table-of-contents)\n\n## Helpers functions\n\nThe module gives you an helpers to perform some basic mongo-related operations.\n\nJust import the class from the module\n\n```typescript\nimport { MongoUtils } from '@hapiness/mongo'\n```\n\nThere is 4 static functions (for now)\n\n`public static prepareUpdateObject(dto: any): any`: Give to this function an object like `{ \"meta\": { \"key\": \"value\" } }` and it returns you the object `{ \"meta.key\": \"value\" }`. Very usefull to perform update operations!\n\n`public static toObjectId(id: string)`: Returns an ObjectID type from the given string (`null` if the string is not a valid ObjectID)\n\n`public static fieldsStringFromArray(fields: string[]): string`: If you want to select only some fields and you need for that to compute a string from an array of string, use this function\n\n`public static filterFindCondition(condition: any): any`: If you have a query object for mongo, this function will parse your condition, convert the field `id` into `_id` and then convert `_id` to an `ObjectID` before giving back the query object\n\n[Back to top](#table-of-contents)\n\n## Contributing\n\nTo set up your development environment:\n\n1. clone the repo to your workspace,\n2. in the shell `cd` to the main folder,\n3. hit `npm or yarn install`,\n4. run `npm or yarn run test`.\n    * It will lint the code and execute all tests.\n    * The test coverage report can be viewed from `./coverage/lcov-report/index.html`.\n\n[Back to top](#table-of-contents)\n\n## Change History\n\n* v2.1.0\n    * Now set by default `useNewUrlParser: true`, `useCreateIndex: true` and `useFindAndModify: false` on the connectionOptions of mongoose.\n* v2.0.2\n    * More debug and events for mongoose adapter\n* v2.0.1\n    * Fix Mongo Utils - prepareUpdateObject\n* v2.0.0\n    * Updated mongoose to latest version\n    * Removed the call to createConnection from the constructor of mongo adapter.\n    * Now catch connection errors and pipe them out to be catch by user later on. No more waiting for timeout to realize there is a connection error.\n    * MongooseGridfsAdapter is now deprecated. Use MongooseGridfsBucketAdapter\n* v1.2.0 (2018-04-05)\n    * Updated packages' versions.\n    * added support of `OnShutdown` of `hapiness Core`\n    * added `close` functions to adapters.\n    * Fix typos in documentation.\n* v1.1.3 (2018-01-16)\n    * Fix get adapter using adapter name\n* v1.1.2 (2018-01-09)\n    * Latest packages' versions.\n    * Added connectionName options to identify an adapter by an alias\n    * Bug fix on an `indexOf !== 1` instead of `indexOf !== -1`\n    * Documentation.\n* v1.1.1 (2017-12-12)\n    * Latest packages' versions.\n    * Add field `collectionName` to force using a specific name for a collection.\n    * Fix key computation when retrieving an adapter.\n    * Allow developers to not give all options for the adapter when getting a document.\n    * Documentation.\n* v1.1.0 (2017-11-20)\n    * Latest packages' versions.\n    * Update Module + Tests related to latest `core` version.\n    * Documentation.\n    * Change packaging process.\n* v1.0.0 (2017-11-14)\n    * `MongoDB` module implementation.\n    * Tests module API.\n    * Documentation.\n\n[Back to top](#table-of-contents)\n\n## Maintainers\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd colspan=\"5\" align=\"center\"\u003e\u003ca href=\"https://www.tadaweb.com\"\u003e\u003cimg src=\"http://bit.ly/2xHQkTi\" width=\"117\" alt=\"tadaweb\" /\u003e\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/Juneil\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/6546204?v=3\u0026s=117\" width=\"117\"/\u003e\u003c/a\u003e\u003c/td\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/antoinegomez\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/997028?v=3\u0026s=117\" width=\"117\"/\u003e\u003c/a\u003e\u003c/td\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/reptilbud\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/6841511?v=3\u0026s=117\" width=\"117\"/\u003e\u003c/a\u003e\u003c/td\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/njl07\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/1673977?v=3\u0026s=117\" width=\"117\"/\u003e\u003c/a\u003e\u003c/td\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/xmaIIoc\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/1898461?s=117\u0026v=4\" width=\"117\"/\u003e\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/Juneil\"\u003eJulien Fauville\u003c/a\u003e\u003c/td\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/antoinegomez\"\u003eAntoine Gomez\u003c/a\u003e\u003c/td\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/reptilbud\"\u003eSébastien Ritz\u003c/a\u003e\u003c/td\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/njl07\"\u003eNicolas Jessel\u003c/a\u003e\u003c/td\u003e\n        \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/xmaIIoc\"\u003eFlorent Bennani\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n[Back to top](#table-of-contents)\n\n## License\n\nCopyright (c) 2017 **Hapiness** Licensed under the [MIT license](https://github.com/hapinessjs/mongo-module/blob/master/LICENSE.md).\n\n[Back to top](#table-of-contents)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapinessjs%2Fmongo-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhapinessjs%2Fmongo-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapinessjs%2Fmongo-module/lists"}