{"id":16471815,"url":"https://github.com/samayun/mongocat","last_synced_at":"2025-09-01T12:42:39.792Z","repository":{"id":188271516,"uuid":"547703886","full_name":"samayun/mongocat","owner":"samayun","description":"Easy to use, configuration based Denormalization mongoose plugin for read heavy applications. Mongocat will reduce your write complexity too.","archived":false,"fork":false,"pushed_at":"2022-10-17T12:33:32.000Z","size":635,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-30T08:17:50.540Z","etag":null,"topics":["denormalization","denormalization-mongoose","denormalize","read-heavy"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/mongocat","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/samayun.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}},"created_at":"2022-10-08T06:02:33.000Z","updated_at":"2023-10-21T01:36:05.000Z","dependencies_parsed_at":"2023-08-14T17:08:31.949Z","dependency_job_id":null,"html_url":"https://github.com/samayun/mongocat","commit_stats":null,"previous_names":["samayun/mongocat"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samayun%2Fmongocat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samayun%2Fmongocat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samayun%2Fmongocat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samayun%2Fmongocat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samayun","download_url":"https://codeload.github.com/samayun/mongocat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238508638,"owners_count":19484168,"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":["denormalization","denormalization-mongoose","denormalize","read-heavy"],"created_at":"2024-10-11T12:14:48.424Z","updated_at":"2025-02-12T16:31:15.953Z","avatar_url":"https://github.com/samayun.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch2 align=\"center\"\u003e ✨ \u003cb\u003eMongoCat\u003c/b\u003e 😺 \u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg \n    src=\"./docs/logo.png\"\n    alt=\"Mongocat\"\n    height=\"150px\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/issues/samayun/mongocat\" alt=\"Issues\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/forks/samayun/mongocat\" alt=\"Forks\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/stars/samayun/mongocat?color=%2312ff65\u0026label=Stars\u0026logo=Star\u0026logoColor=green\u0026style=flat\" alt=\"Stars\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/license/samayun/mongocat\" alt=\"License\"\u003e\n\u003c/p\u003e\n\nEasy to use, configuration based \u003cb\u003eDenormalization mongoose plugin\u003c/b\u003e for read heavy applications. Mongocat will reduce your write complexity too.\n\n### Installation\n\n- `npm i mongocat`\n\n### Why mongocat?\n\n- When a mid scale application are so read heavy and need an emergency solution.\n\n### Advantages\n\n- application performs well for many requests\n\n- easy to find, filter read operations\n\n- easy to setup\n\n- declarative approach\n\n- maintainability - you have to manage configuration only\n\n- very easy to sync\n\n- frequently requirement change is not nightmare here\n\n- Denormalize as you really need\n\n- Single source of truth. Third party source of document updates is easily synced by mongocat\n\n### Disadvantages\n\n- write operations are so slow\n\n- too much abstraction- denormalizable operations are hidden from business logic.\n\n- write operations are expensive \u0026 have to handle sensitively\n\n- it's behave like sql for strict mode. If foreign key doesn't exist write operation will fail. (\n  it's a good advantage for data consistency too\n  )\n\n#### Requirement\n\n- Firstly generate boilerplate \u0026 connect to database (mongodb via Mongoose ODM)\n\n- Mongoose version must be greater than 6.x.x\n\n- For existing project use mongocat-sync to migrate to denormable schema (We are working on it, it's not available yet)\n\n- Setup providers \u0026 consumers carefully\n\n- Follow linear approach, one collection can consume many denormalized data from many provider\n\n- A provider can consume many denormalized data from other providers too but never create big bang\n\n- Big bang creates when you are consuming from a collection at the same time provider denorbmalized data to that consumer too.\n\n## Documentation\n\n#### Provider\n\n```js\nimport { provider } from 'mongocat';\n\nconst CategorySchema = new Schema(\n  {\n    title: String,\n    slug: String,\n    icon: String,\n    status: String,\n  },\n  { timestamps: true }\n);\n\nCategorySchema.plugin(\n  provider({\n    toRef: 'Category',\n    keyFields: ['title', 'slug', 'icon'],\n    ignoredFields: ['status'],\n  })\n);\n\nexport const Category = model('Category', CategorySchema);\n```\n\n```js\nimport { provider } from 'mongocat';\n\nconst UserSchema = new Schema(\n  {\n    name: String,\n    username: String,\n    email: String,\n    status: String,\n  },\n  { timestamps: true }\n);\n\nUserSchema.plugin(\n  provider({\n    toRef: 'User',\n    keyFields: ['name', 'username', 'email', 'status'],\n  })\n);\n\nexport const User = model('User', UserSchema);\n```\n\n#### Consumer\n\n```js\nimport { watchConsumer } from 'mongocat';\n\nconst BlogSchema = new Schema({\n  title: String,\n  slug: String,\n  category: new Schema({\n    _id: {\n      type: Schema.Types.ObjectId,\n      ref: 'Category',\n    },\n    title: String,\n    slug: String,\n    icon: String,\n  }),\n  status: Boolean,\n});\n\nBlogSchema.plugin(\n  watchConsumer({\n    toPath: 'category',\n    key: '_id',\n    strict: true,\n    fromRef: 'Category',\n    toRef: 'Blog',\n    changeStreamEnabled: false, // sync updatesfrom third party source\n  })\n);\n\nexport const Blog = model('Blog', BlogSchema);\n```\n\n### Frontend Payloads\n\n- Blog:\n\n  ```js\n    {\n       title: \"Mongocat is joss\",\n       category: {\n          _id: \"62960300da98cc1aba3e9ee2\"\n       },\n       status: true\n    }\n  ```\n\n```js\n  {\n     title: \"Docker is joss\",\n     category: {\n        _id: \"62960300da98cc1aba3e9ee2\"\n     },\n     tags: [\n      { _id: \"62960300da98cc1aba3e9ee2\" },\n      { _id: \"62960300da98cc1aba3e9ee2\" }\n     ],\n     status: true\n  }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamayun%2Fmongocat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamayun%2Fmongocat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamayun%2Fmongocat/lists"}