{"id":22092195,"url":"https://github.com/pirxpilot/mniam","last_synced_at":"2025-03-23T23:45:29.198Z","repository":{"id":5989032,"uuid":"7211419","full_name":"pirxpilot/mniam","owner":"pirxpilot","description":"Yet another mongodb native driver facade.","archived":false,"fork":false,"pushed_at":"2024-04-05T15:50:49.000Z","size":108,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-01T22:48:12.624Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/pirxpilot.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":"License.txt","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":"2012-12-17T20:14:04.000Z","updated_at":"2022-05-17T04:31:31.000Z","dependencies_parsed_at":"2024-04-05T16:56:28.518Z","dependency_job_id":null,"html_url":"https://github.com/pirxpilot/mniam","commit_stats":{"total_commits":109,"total_committers":4,"mean_commits":27.25,"dds":"0.45871559633027525","last_synced_commit":"e1072131b55a999e954ea2327bbdb4ee254d83f9"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Fmniam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Fmniam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Fmniam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Fmniam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pirxpilot","download_url":"https://codeload.github.com/pirxpilot/mniam/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186926,"owners_count":20574554,"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-12-01T03:08:37.916Z","updated_at":"2025-03-23T23:45:29.177Z","avatar_url":"https://github.com/pirxpilot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version][npm-image]][npm-url]\n[![Build Status][build-image]][build-url]\n[![Dependency Status][deps-image]][deps-url]\n\n# mniam\n\n\nYet another [mongodb][] [native driver][2] facade.\nTakes care of:\n\n- mongo URI parsing\n- opening and closing DB connections\n- opening collections\n\nInstall by running\n\n    npm install mniam\n\n## API\n\n\n### `database(url, [options])`\n\nConnect to database `mniam-test` and create `friends` collection with index on ```name``` field.\n\n```javascript\nconst db = database('mongodb://localhost/mniam-test');\nconst friends = db.collection({\n  name: 'friends',\n  indexes: [[{ name: 1 }]]\n});\n```\n\nMniam is using [MongoClient][3] to establish the connection: [full mongo database URLs][4] are\nsupported. The database function also takes a hash of options divided into db/server/replset/mongos\nallowing you to tweak options not directly supported by the unified url string format.\n\n```javascript\nconst db = database('mongodb://localhost/mniam-test', {\n  db: {\n    w: -1\n  },\n  server: {\n    ssl: true\n  }\n});\n```\n\n### `collection.save`\n\nAdd a new documents:\n\n```javascript\nconst item = await friends.save({\n  name: 'Alice',\n  age: 14,\n};\nconsole.log('Item id:', item._id);\n```\n\n### `collection.findOneAndUpdate`\n\nUpdate a document:\n\n```javascript\nconst item = await friends.findAndModify({ _id: item._id }, {\n  $set: { age: 15 }\n});\nconsole.log('Alice is now:', item.age);\n```\n\n### `collection.deleteOne`\n\nRemove a document:\n\n```javascript\nawait friends.deleteOne({ name: 'Alice' });\n```\n\n### Iteration\n\nUse `query`, `fields` and `options` to create and configure cursor.\nIterate over the results of the query using `toArray`, `eachSeries`, `eachLimit` methods.\n\n- `items` - can be used as async iterator\n\n```javascript\nfor await (const friend of friends.query({ age: { $gt: 21 } }).items()) {\n  console.log('My friend over 21 years old', friend.name);\n}\n```\n\n- `toArray` - converts query results into array\n\n```javascript\nconst arr = await friends.query({ age: { $gt: 21 } }).toArray();\nconsole.log('My friends over 21 years old', arr);\n```\n\n- `eachSeries` - calls `onItem` sequentially for all results\n\n```javascript\nawait friends\n  .query()\n  .fields({ name: 1 })\n  .eachSeries(async item =\u003e console.log('Name:', item.name));\nconsole.log('All friends listed.');\n```\n\n- `eachLimit` - iterates over all results calling `onItem` in parallel, but no more than `limit` at a time\n\n```javascript\nawait friends\n  .query()\n  .options({ sort: { age: 1 } })\n  .eachLimit(4, async item =\u003e console.log('Friend', item));\nconsole.log('All friends listed.');\n```\n\n### Aggregation\n\nMniam collections provides flex API for [aggregation] pipeline:\n\n```javascript\nconst results = await friends\n  .aggregate()      // start pipeline\n  .project({ author: 1, tags: 1 })\n  .unwind('$tags')\n  .group({\n    _id : { tags : '$tags' },\n    authors : { $addToSet : '$author' },\n    count: { $sum: 1 }\n  })\n  .sort({ count: -1 })\n  .toArray();\nconsole.log(results);\n```\n\nIn addition to `toArray` you can use `eachSeries` and `eachLimit` to iterate over aggregation results.\nEach aggregation stage (`$project`, `$unwind`, `$sort`, etc.) has a corresponding function with the same\nname (without `$`). You can also pass a traditional array of stages to `.pipeline(stages)` method, and set\noptions with `.options({})` method.\n\n## License\n\nMIT\n\n[mongodb]: http://www.mongodb.org\n[2]: http://github.com/mongodb/node-mongodb-native.git\n[3]: http://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html\n[4]: http://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html#the-url-connection-format\n[aggregation]: https://docs.mongodb.com/manual/core/aggregation-pipeline/\n\n[npm-url]: https://npmjs.org/package/mniam\n[npm-image]: https://img.shields.io/npm/v/mniam\n\n[build-url]: https://github.com/pirxpilot/mniam/actions/workflows/check.yaml\n[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/mniam/check.yaml?branch=main\n\n[deps-image]: https://img.shields.io/librariesio/release/npm/mniam\n[deps-url]: https://libraries.io/npm/mniam\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirxpilot%2Fmniam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpirxpilot%2Fmniam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirxpilot%2Fmniam/lists"}