{"id":18926838,"url":"https://github.com/ladjs/mongoose","last_synced_at":"2025-04-15T13:33:28.013Z","repository":{"id":25019236,"uuid":"102993798","full_name":"ladjs/mongoose","owner":"ladjs","description":"Mongoose helper for Lad","archived":false,"fork":false,"pushed_at":"2024-07-11T20:28:04.000Z","size":546,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T02:01:54.178Z","etag":null,"topics":["connection","events","graceful","koa","mongo","mongoose","reconnect","reconnection"],"latest_commit_sha":null,"homepage":"https://lad.js.org","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/ladjs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-10T00:47:22.000Z","updated_at":"2024-07-11T20:28:07.000Z","dependencies_parsed_at":"2023-02-19T02:01:15.212Z","dependency_job_id":null,"html_url":"https://github.com/ladjs/mongoose","commit_stats":{"total_commits":89,"total_committers":5,"mean_commits":17.8,"dds":0.5168539325842696,"last_synced_commit":"15927b8cd54bdefc0ef29d9b77cfc644640a7729"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fmongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/mongoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249080494,"owners_count":21209537,"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":["connection","events","graceful","koa","mongo","mongoose","reconnect","reconnection"],"created_at":"2024-11-08T11:17:19.484Z","updated_at":"2025-04-15T13:33:27.733Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [**@ladjs/mongoose**](https://github.com/ladjs/mongoose)\n\n[![build status](https://github.com/ladjs/mongoose/actions/workflows/ci.yml/badge.svg)](https://github.com/ladjs/mongoose/actions/workflows/ci.yml)\n[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://github.com/lassjs/lass)\n[![license](https://img.shields.io/github/license/ladjs/mongoose.svg)](LICENSE)\n\n\u003e Mongoose helper for [Lad][], which is used as an alternative to the default `mongoose.connect()` for multiple connection management.  See the [Forward Email][forward-email] codebase for further insight into setup.\n\n\n## Table of Contents\n\n* [Install](#install)\n* [Usage](#usage)\n* [Options](#options)\n* [Contributors](#contributors)\n* [License](#license)\n\n\n## Install\n\n\u003e **Requires mongoose v6+ to be a dependency in your project.**\n\n[npm][]:\n\n```sh\nnpm install @ladjs/mongoose mongoose\n```\n\n\n## Usage\n\n```js\nconst Mongoose = require('@ladjs/mongoose');\nconst { Schema } = require('mongoose');\n\n(async () =\u003e {\n  const m = new Mongoose({\n    mongo: {\n      options: { heartbeatFrequencyMS: 100, serverSelectionTimeoutMS: 1000 }\n    }\n  });\n\n  const conn1 = await m.createConnection('mongodb://server-one.example.com/database-name').asPromise();\n  const conn2 = await m.createConnection('mongodb://server-two.example.com/database-name').asPromise();\n\n  const UserSchema = new Schema({ name: String });\n  const LogSchema = new Schema({ name: String });\n\n  const Users = conn1.model('Users', UserSchema);\n  const Logs = conn2.model('Logs', LogSchema);\n\n  // write to the server-one.example.com database\n  await Users.create({ name: 'test' });\n\n  // write to the server-two.example.com database\n  await Logs.create({ name: 'test' });\n})();\n```\n\nNote that instances of this class `Mongoose` only have the method `createConnection`.  It is not 1:1 with `mongoose` normal singleton.\n\nYou should use [@ladjs/graceful][lad-graceful] to manage process SIGHUP and graceful exits.\n\n\n## Options\n\n| Option                           | Type                      | Default                                                                         | Description                                                                                                                                                                                                                                                                                                                                                                                                  |\n| -------------------------------- | ------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `logger`                         | Object                    | `console`                                                                       | Custom logger function, see [cabin][] or [axe][] as a default if desired.                                                                                                                                                                                                                                                                                                                                    |\n| `mongo`                          | Object                    | ---                                                                             | See below `uri` and `options` properties.                                                                                                                                                                                                                                                                                                                                                                    |\n| `mongo.uri`                      | String                    | undefined                                                                       | mongo connection URI \u003cbr/\u003e which is passed as the first argument to `mongoose.createConnection` \u003cbr/\u003esee [mongo options docs](https://docs.mongodb.com/drivers/node/current/fundamentals/connection/#connection-options)                                                                                                                                                                                     |\n| `mongo.options`                  | Object                    | undefined                                                                       | mongo connection options \u003cbr/\u003e which is passed as the second argument to `mongoose.createConnection` \u003cbr/\u003esee [mongo options docs](https://docs.mongodb.com/drivers/node/current/fundamentals/connection/#connection-options)                                                                                                                                                                                |\n| `bindEvents`                     | Boolean                   | `true`                                                                          | Whether or not to bind default events to the Mongoose connection using provided `logger`.                                                                                                                                                                                                                                                                                                                    |\n| `hideMeta`                       | String or `false` Boolean | `\"hide_meta\"`                                                                   | Appends a `true` boolean property to a property with this value in logs, e.g. `console.log('mongoose disconnected', { hide_meta: true });` which is useful for preventing metadata object from being invoked as the second argument (this is meant for usage with [Cabin][] and [Axe][] and made for [Forward Email][forward-email]). If you pass a `false` value then this property will not get populated. |\n| ---                              | ---                       | ---                                                                             | ---                                                                                                                                                                                                                                                                                                                                                                                                          |\n| `allowDiskUse`                   | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `applyPluginsToChildSchemas`     | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `applyPluginsToDiscriminators`   | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `autoCreate`                     | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `autoIndex`                      | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `bufferCommands`                 | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `bufferTimeoutMS`                | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `debug`                          | Boolean                   | If `process.env.MONGOOSE_DEBUG` is truthy, then it is `true`, otherwise `false` | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `id`                             | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `timestamps.createdAt.immutable` | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `maxTimeMS`                      | Number                    | `10000`                                                                         | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `objectIdGetter`                 | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `overwriteModels`                | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `returnOriginal`                 | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `runValidators`                  | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `sanitizeFilter`                 | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `selectPopulatedPaths`           | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `strict`                         | Boolean                   | `true`                                                                          | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `strictQuery`                    | Boolean                   | `true`                                                                          | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `toJSON`                         | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n| `toObject`                       | Boolean                   | undefined                                                                       | set with [mongoose.set][mongoose.set]                                                                                                                                                                                                                                                                                                                                                                        |\n\n\n## Contributors\n\n| Name               | Website                   |\n| ------------------ | ------------------------- |\n| **Nick Baugh**     | \u003chttp://niftylettuce.com\u003e |\n| **Spencer Snyder** | \u003chttp://spencersnyder.io\u003e |\n\n\n## License\n\n[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com)\n\n\n##\n\n[npm]: https://www.npmjs.com/\n\n[lad]: https://lad.js.org\n\n[mongoose.set]: https://mongoosejs.com/docs/api/mongoose.html#mongoose_Mongoose-set\n\n[cabin]: https://github.com/cabinjs/cabin\n\n[axe]: https://github.com/cabinjs/axe\n\n[forward-email]: https://github.com/forwardemail/forwardemail.net\n\n[lad-graceful]: https://github.com/ladjs/graceful\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fmongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fmongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fmongoose/lists"}