{"id":16223727,"url":"https://github.com/lykmapipo/mongoose-common","last_synced_at":"2025-06-30T09:34:21.612Z","repository":{"id":33788571,"uuid":"160926177","full_name":"lykmapipo/mongoose-common","owner":"lykmapipo","description":"Re-usable helpers for mongoose","archived":false,"fork":false,"pushed_at":"2023-01-09T00:25:47.000Z","size":1946,"stargazers_count":8,"open_issues_count":9,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T23:40:39.551Z","etag":null,"topics":["clear","connect","disconnect","drop","helpers","jsonschema","lykmapipo","model","mongoose","path","utilitities"],"latest_commit_sha":null,"homepage":null,"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/lykmapipo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2018-12-08T09:59:25.000Z","updated_at":"2025-01-20T20:51:32.000Z","dependencies_parsed_at":"2023-01-15T02:33:18.975Z","dependency_job_id":null,"html_url":"https://github.com/lykmapipo/mongoose-common","commit_stats":null,"previous_names":[],"tags_count":108,"template":false,"template_full_name":null,"purl":"pkg:github/lykmapipo/mongoose-common","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lykmapipo","download_url":"https://codeload.github.com/lykmapipo/mongoose-common/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-common/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260059339,"owners_count":22953050,"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":["clear","connect","disconnect","drop","helpers","jsonschema","lykmapipo","model","mongoose","path","utilitities"],"created_at":"2024-10-10T12:19:53.610Z","updated_at":"2025-06-15T22:09:27.850Z","avatar_url":"https://github.com/lykmapipo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-common\n\n[![Build Status](https://app.travis-ci.com/lykmapipo/mongoose-common.svg?branch=master)](https://app.travis-ci.com/lykmapipo/mongoose-common)\n[![Dependencies Status](https://david-dm.org/lykmapipo/mongoose-common.svg)](https://david-dm.org/lykmapipo/mongoose-common)\n[![Coverage Status](https://coveralls.io/repos/github/lykmapipo/mongoose-common/badge.svg?branch=master)](https://coveralls.io/github/lykmapipo/mongoose-common?branch=master)\n[![GitHub License](https://img.shields.io/github/license/lykmapipo/mongoose-common)](https://github.com/lykmapipo/mongoose-common/blob/develop/LICENSE)\n\n[![Commitizen Friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![Code Style](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)\n[![npm version](https://img.shields.io/npm/v/@lykmapipo/mongoose-common)](https://www.npmjs.com/package/@lykmapipo/mongoose-common)\n\nRe-usable helpers for mongoose\n\n**Note: This version no longer support [mongoose-schema-jsonschema](https://github.com/DScheglov/mongoose-schema-jsonschema)**\n\n## Requirements\n\n- [NodeJS v13+](https://nodejs.org)\n- [Npm v6.12+](https://www.npmjs.com/)\n- [MongoDB v4+](https://www.mongodb.com/)\n- [Mongoose v6+](https://github.com/Automattic/mongoose)\n\n## Install\n```sh\n$ npm install --save mongoose @lykmapipo/mongoose-common\n```\n\n## Usage\n\n```javascript\nimport mongoose from 'mongoose';\nimport {\n  connect,\n  clear,\n  syncIndexes,\n  disconnect,\n  drop\n} from '@lykmapipo/mongoose-common';\n\nconnect(error =\u003e { ... });\n\nclear(error =\u003e { ... });\n\nsyncIndexes(error =\u003e { ... });\n\ndrop(error =\u003e { ... });\n\ndisconnect(error =\u003e { ... });\n\n...\n\n```\n\n## API\n\n### `connect([url: String], done: Function)`\nEstablish connection using provided connection string or `process.env.MONGODB_URI`.\n\nExample:\n```js\nconnect((error) =\u003e { ... });\n```\n\n### `clear([connection:Connection], [...modelNames: String], done: Function)`\nClear data of specified `modelNames`. If none provided all models will be cleared. If `connection` not provided default mongoose connection will be used.\n\nExample\n```js\nclear((error) =\u003e { ... });\nclear('User', (error) =\u003e { ... });\nclear('User', 'Profile', (error) =\u003e { ... });\n```\n\n### `drop([connection: Connection], done: Function)`\nDeletes the test database, including all collections, documents, and indexes. If `connection` not provided default mongoose connection will be used.\n\nExample\n```js\ndrop((error) =\u003e { ... });\ndrop(connection, (error) =\u003e { ... });\n```\n\n### `disconnect([connection: Connection], done: Function)`\nClose all connections or provided connection\n\nExample\n```js\ndisconnect((error) =\u003e { ... }); //close all\ndisconnect(connection, (error) =\u003e { ... }); //close provided\n```\n\n### `model([name: String], [schema: Schema], [connection: Connection])`\nTry to obtain existing model or register new model safely. If `connection` not provided default mongoose connection will be used.\n\nExample\n```js\nconst User = model('User'); // get safely\nconst User = model('User', schema); // get or register safely\nconst random = model(schema); // register random model safely\nconst User = model('User', schema, connection); // get or register safely\n```\n\n### `eachPath(schema: Schema, iteratee: Function)`\nIterate recursively on schema primitive paths and invoke provided iteratee function.\n\nExample\n```js\neachPath(schema, (path, schemaType) =\u003e { ... });\n```\n\n### `path(pathName: String)`\nA shortcut to obtain schema path from model.\n\nExample\n```js\nUser.path('name');\nUser.path('name.given');\nUser.path('name.surname');\n```\n\n### `isObjectId(value: Any)`\nCheck if provided value is an instance ObjectId\n\nExample\n```js\nconst _isObjectId = isObjectId(value);\n```\n\n### `isMap(value: Any)`\nCheck if provided value is an instance MongooseMap\n\nExample\n```js\nconst _isMap = isMap(value);\n```\n\n### `isInstance(value: Any)`\nCheck if provided value is an mongoose model instance\n\nExample\n```js\nconst _isInstance = isInstance(value);\n```\n\n### `copyInstance(value: Any)`\nCopy and return plain object of mongoose model instance\n\nExample\n```js\nconst copyOfInstance = copyInstance(value);\n```\n\n### `isSchema(value: Any)`\nCheck if provided value is an mongoose schema instance\n\nExample\n```js\nconst _isSchema = isSchema(value);\n```\n\n### `isConnection(value: Any)`\nCheck if provided value is an mongoose connection instance\n\nExample\n```js\nconst _isConnection = isConnection(value);\n```\n\n### `isConnected(connection: Connection)`\nCheck state of provided mongoose connection if is `connected`.\n\nExample:\n```js\nconst connected = isConnected(conn);\n```\n\n### `toCollectionName(modelName: String)`\nProduces a collection name of provided model name.\n\nExample:\n```js\nconst collectionName = toCollectionName('User'); // =\u003e users\n```\n\n\n## Environment\n```js\nSEED_PATH=`${process.cwd}/seeds`\nSEED_FRESH=false\n```\n\n## Testing\n* Clone this repository\n\n* Install all development dependencies\n```sh\n$ npm install\n```\n* Then run test\n```sh\n$ npm test\n```\n\n## Contribute\nIt will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) CodeTanzania \u0026 Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykmapipo%2Fmongoose-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flykmapipo%2Fmongoose-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykmapipo%2Fmongoose-common/lists"}