{"id":28821319,"url":"https://github.com/corgi-it/mongoose-repo","last_synced_at":"2026-05-06T18:35:34.946Z","repository":{"id":57150963,"uuid":"76132234","full_name":"Corgi-IT/mongoose-repo","owner":"Corgi-IT","description":"A Mongoose Repository Class","archived":false,"fork":false,"pushed_at":"2018-02-20T01:44:44.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-18T22:06:18.111Z","etag":null,"topics":["database","mongoose","repository"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Corgi-IT.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":"2016-12-10T19:12:06.000Z","updated_at":"2017-03-08T20:20:18.000Z","dependencies_parsed_at":"2022-08-27T05:52:39.259Z","dependency_job_id":null,"html_url":"https://github.com/Corgi-IT/mongoose-repo","commit_stats":null,"previous_names":["geexteam/mongoose-repo"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/Corgi-IT/mongoose-repo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corgi-IT%2Fmongoose-repo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corgi-IT%2Fmongoose-repo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corgi-IT%2Fmongoose-repo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corgi-IT%2Fmongoose-repo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Corgi-IT","download_url":"https://codeload.github.com/Corgi-IT/mongoose-repo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Corgi-IT%2Fmongoose-repo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268065766,"owners_count":24190184,"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-07-31T02:00:08.723Z","response_time":66,"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":["database","mongoose","repository"],"created_at":"2025-06-18T22:06:17.608Z","updated_at":"2026-05-06T18:35:34.910Z","avatar_url":"https://github.com/Corgi-IT.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoose-Repo (morepo)\nA Mongoose Repository Class\n\n[![Build Status](https://travis-ci.org/Geexteam/mongoose-repo.svg?branch=master)](https://travis-ci.org/Geexteam/mongoose-repo)\n[![Dependency Status](https://gemnasium.com/badges/github.com/Geexteam/mongoose-repo.svg)](https://gemnasium.com/github.com/Geexteam/mongoose-repo)\n[![NSP Status](https://nodesecurity.io/orgs/geex-team/projects/124c6964-bd3c-4b82-ae9b-633df613c8bb/badge)](https://nodesecurity.io/orgs/geex-team/projects/124c6964-bd3c-4b82-ae9b-633df613c8bb)\n\n\n## Requirements ##\nMake sure you're using Nodejs 8.x or higher, for `async/await` to work\n\nIf you're working on Nodejs 6.x, please install morepo version 0.8\n\n## Installation ##\n\nYou can install this module with NPM:\n\n    npm install --save morepo\n\n## Getting started ##\nYou can use this class like it is or make a specific Repository class that extends this class\n\n### Usecase 1: ###\n```ES8\nconst mongoose = require('mongoose');\nconst Repository = require('morepo');\n\nconst postRepo = new Repository(mongoose.model('Post'));\n```\n\n### Usecase 2: ###\n```ES8\nconst mongoose = require('mongoose');\nconst Repository = require('morepo');\n\nclass PostRepository extends Repository {\n\n    constructor(model) {\n        super(model || mongoose.model('Post'));\n    }\n\n    // Override an existing function to add some custom functionality\n    async findByObjectId(objectId) {\n        try {\n            if (!objectId) {\n                return {error: 'No ObjectId given'};\n            }\n\n            const body = await this.find(\n                {_id: objectId},\n                this.generateOptions({multiple: false})\n            );\n            if (body === null) {\n                return {error: 'No posts found'};\n            }\n            return body;\n        } catch (error) {\n\n            return {error: error.message};\n        }\n    }\n\n    generateOptions(options) {\n        const base = {\n            populate: [\n                {path: 'author', select: '-password -registration_date -__v'},\n                {path: 'comments'}\n            ],\n            sort: {date_created: 'descending'},\n            multiple: true\n        };\n        return super.generateOptions(base, options);\n    }\n}\n\nconst postRepo = new PostRepository(mongoose.model('Post'));\n```\n\n## Functions ##\n### Constructor ###\nCreates a new instance of the Repository\n\n#### Params ####\n- model - Mongoose Model\n- Options:\n  - applyStatics - default: true\n    Applies all static model functions to the Repo\n\n#### Returns ####\nNew instance of the Repository\n\n### create ###\n#### Params ####\n- obj - Object to save to the database\n\n#### Returns ####\nGiven object saved to the database\n\n### find ###\nExecutes the given query\n\n#### Params ####\n- query - Object\n- Options:\n  - select\n  - populate\n    - If something else than an Array, String or Object is given, the value is skipped\n    - Examples\n     Populate examples:\n     String: `created_by`\n     Object (with multilevel populate):\n         ```JS\n         {\n            path: 'friends',\n            // Get friends of friends - populate the 'friends' array for every friend\n            populate: { path: 'friends' }\n         }\n         ```\n     Array: `[One of the 2 above]`\n  - limit\n  - skip\n  - sort\n  - lean - default: false\n  - count - default: false\n  - multiple - default: true\n\n#### Returns ####\nQuery result\nIf `multiple` is `true`: it'll return an `Array`, else it'll return an `Object`\n\n### findByObjectId ###\nLooks for 1 document based on the objectId\n\n#### Params ####\n- query - Object\n- Options:\n  - select\n  - populate\n  - lean - default: false\n\n#### Returns ####\nThe request document\n\n### findAll ###\nRetrieves all documents in that collection\n\n#### Params ####\nnone\n\n#### Returns ####\nArray with all documents in that collection\n\n### update ###\nRetrieves a document by it's ID, assigns the new values to it (thanks you lodash) and saves it\n\n#### Params ####\n- objectId - Object || String\n- newValues - Object\n\n#### Returns ####\nThe updated document\n\n### remove ###\nRemoves the document identified by the given ObjectID from the collection\n\n#### Params ####\n- objectId - Object || String\n\n#### Returns ####\nThe remove's result\n\n\n\n## Roadmap ##\n\nv1.0.0\n- Tests\n- Folder with examples\n- Better Doc and readme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorgi-it%2Fmongoose-repo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorgi-it%2Fmongoose-repo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorgi-it%2Fmongoose-repo/lists"}