{"id":17349237,"url":"https://github.com/co2-git/mungo","last_synced_at":"2025-06-28T09:36:25.693Z","repository":{"id":68259027,"uuid":"44822304","full_name":"co2-git/mungo","owner":"co2-git","description":"Database Model in JS for MongoDB","archived":false,"fork":false,"pushed_at":"2016-04-23T02:29:59.000Z","size":321,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T11:44:45.887Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/co2-git.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2015-10-23T15:41:36.000Z","updated_at":"2016-01-12T06:30:16.000Z","dependencies_parsed_at":"2023-02-22T21:15:35.142Z","dependency_job_id":null,"html_url":"https://github.com/co2-git/mungo","commit_stats":null,"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"purl":"pkg:github/co2-git/mungo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fmungo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fmungo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fmungo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fmungo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/co2-git","download_url":"https://codeload.github.com/co2-git/mungo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fmungo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262406946,"owners_count":23306285,"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":[],"created_at":"2024-10-15T16:55:07.583Z","updated_at":"2025-06-28T09:36:25.674Z","avatar_url":"https://github.com/co2-git.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Mungo\n===\n\n[![Build Status](https://travis-ci.org/co2-git/badges.svg?branch=master)](https://travis-ci.org/co2-git/badges)\n\n`Mungo` is a ORM for MongoDB written in NodeJS.\n\n# Install\n\n```bash\nnpm install mungo\n```\n\n# Usage\n\n```js\nimport Mungo from 'mungo';\n\nclass User extends Mungo.Model {\n  static schema = { username : String };\n}\n\n// Connect to MongoDB\nMungo.connect('mongodb://@localhost');\n\nUser.create({ username : 'dude' });\n\nUser.find({ username : 'dude' });\n\nUser.update({ username : 'dude' }, { username : 'mate' });\n\nUser.remove({ username : 'dude' });\n```\n\n# Syntax\n\nAll operations are promises:\n\n```js\nFoo.find()\n  .then(found =\u003e { /*...*/ })\n  .catch(error =\u003e { /*...*/ });\n```\n\nSome methods are chainable:\n\n```js\nFoo\n  .find({ foo : 1 })\n  .limit(25)\n  .then(found =\u003e {});\n```\n\n# Connect\n\n```js\nMungo.connect(url);\n```\n\nConnecting by entering an url. Connect emits so you can listen to it:\n\n```js\nMungo.connect(url)\n  .on('error', error =\u003e console.log(error.stack))\n  .on('connected', connection =\u003e {\n    console.log(connection.db)\n  });\n```\n\nConnections are stacked in `Mungo.connections`. When you try to do a op, the first alive connection in array will be chosen.\n\nYou can force a connection to be used:\n\n```js\nMungo.connect(url1);\nMungo.connect(url2);\n\nFoo.find().connection(0);\nFoo2.find().connection(1);\n```\n\nOr specify the connection directly:\n\n```js\nMungo\n  .connect(url)\n  .on('connected', connection =\u003e Foo.find().connection(connection));\n```\n\n# Methods\n\n| Method | Arguments | About |\n|--------|-----------|-------|\n| `count`| - `\u003cobject\u003e query` default `{}`\u003cbr/\u003e- `\u003cobject\u003e projection` default `{}` \u003cbr/\u003e- `\u003cobject\u003e options` default `{}`| Count documents in collection\n\n\n# Schema\n\n## Type\n\n```js\nclass User extends Mungo.Model {\n  static schema = { username : String, score : Number };\n}\n```\n\n### Types allowed\n\n- `String`\n- `Number`\n- `Boolean`\n- `Date`\n- `Array` *for a better array control, see below*\n- `Object` *for a better subdocument control, see below*\n- `Subdocument` *see below*\n- `ObjectID` *MongoDB's object id*\n- `Mixed` *accepts any type*\n\n### Array of types\n\nYou can enclose types inside arrays:\n\n```js\n// { numbers : [1, 2, 3] }\n\nstatic schema = { numbers : [Number] }\n```\n\n### Sudocuments\n\nUse the `Subdocument` to embed a document:\n\n```js\n// { foo : { bar : true } }\n\nstatic schema = { \"foo\" : new (Mungo.Subdocument)({ \"bar\" : Boolean }) }\n```\n\nYou could also use directly the object notation such as:\n\n```js\n// { foo : { bar : true } }\n\nstatic schema = { \"foo\" : { \"bar\" : Boolean } }\n```\n\nBut **you have to make sure your subdocument does not contain a `type` property** - otherwise it will be mistaken with a field description.\n\n### References to other model\n\nUse the name of the model you want to refer :\n\n```js\nclass Team extends Mungo.Model {\n  static schema = { \"name\" : String };\n}\n\nclass Player extends Mungo.Model {\n  static schema = { \"team\" : Team };\n}\n```\n\n### Cyclic dependencies\n\nIf your model uses references to other models that also refer it (cyclic dependency), you can use the getter syntax to make sure referred models do not end up null.\n\n```js\nstatic get schema () {\n  return { \"team\" : Team };\n}\n```\n\n### Type declaration\n\nYou can use the sugar syntax or the type attribute in the field description:\n\n```js\nstatic schema = { \"name\" : String }\n// Or...\nstatic schema = {\n  name : { \"type\" : String }\n}\n```\n\n### Default type\n\nIf you don't declare a type for a field, `Mixed` is used.\n\n## Required\n\nRequire a fill to be set when inserting to DB\n\n```js\nstatic schema = { \"name\" : { required : true } }\n```\n\n## Default\n\nFill empty field values with default when inserting to DB\n\n```js\nstatic schema = { \"score\" : { default : 0 } }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Fmungo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fco2-git%2Fmungo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Fmungo/lists"}