{"id":15653157,"url":"https://github.com/lmammino/mongo-uri-builder","last_synced_at":"2025-04-14T10:33:06.497Z","repository":{"id":1613932,"uuid":"43246465","full_name":"lmammino/mongo-uri-builder","owner":"lmammino","description":"A node.js module to easily create mongodb connection strings using configuration objects","archived":false,"fork":false,"pushed_at":"2023-03-04T02:47:51.000Z","size":668,"stargazers_count":30,"open_issues_count":13,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T23:41:52.097Z","etag":null,"topics":["javascript","javascript-library","library","mongo-uri-builder","node","node-js","nodejs"],"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/lmammino.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,"governance":null}},"created_at":"2015-09-27T12:54:28.000Z","updated_at":"2023-05-19T08:59:15.000Z","dependencies_parsed_at":"2023-07-06T05:44:19.080Z","dependency_job_id":null,"html_url":"https://github.com/lmammino/mongo-uri-builder","commit_stats":{"total_commits":39,"total_committers":5,"mean_commits":7.8,"dds":"0.28205128205128205","last_synced_commit":"0e16e028219a19c02bebb0cdda0551eb39128a87"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fmongo-uri-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fmongo-uri-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fmongo-uri-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fmongo-uri-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmammino","download_url":"https://codeload.github.com/lmammino/mongo-uri-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248862718,"owners_count":21173867,"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":["javascript","javascript-library","library","mongo-uri-builder","node","node-js","nodejs"],"created_at":"2024-10-03T12:44:50.564Z","updated_at":"2025-04-14T10:33:06.475Z","avatar_url":"https://github.com/lmammino.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongo-uri-builder\n\nA zero dependency Node.js module to easily create MongoDB connection strings using configuration objects\n\n![Tests](https://github.com/lmammino/mongo-uri-builder/workflows/Tests/badge.svg)\n[![npm version](https://badge.fury.io/js/mongo-uri-builder.svg)](http://badge.fury.io/js/mongo-uri-builder)\n[![codecov](https://codecov.io/gh/lmammino/mongo-uri-builder/branch/master/graph/badge.svg)](https://codecov.io/gh/lmammino/mongo-uri-builder)\n\n[![NPM](https://nodei.co/npm/mongo-uri-builder.png)](https://nodei.co/npm/mongo-uri-builder/)\n\n\n## Rationale\n\nMost of the existing MongoDB libraries (e.g. the official MongoClient or Mongoose) uses connection strings to connect to your running mongo instances which most of the times is very quick and convenient.\nAnyway sometime you want to have your MongoDB connection details organized in a nice javascript object so that you can easily serialize it in a configuration file and be able to override some specific values in different environments (e.g. \"development\" or \"production\") without having to override the entire connection string. \n\nWith this module you can easily accomplish this goal and in general you will be able to easily generate a MongoDB connection string starting from an organized javascript object that you can manipulate as you wish.\n\n\n## Quick example\n\n```javascript\nvar mongoUriBuilder = require('mongo-uri-builder');\n\nvar connectionString = mongoUriBuilder({\n\tusername: 'user', // or user: 'user'\n\tpassword: 'pass',\n\thost: 'host1',\n\tport: 1111,\n\treplicas: [\n\t\t{host: 'host2', port: 2222},\n\t\t{host: 'host3', port: 3333}\n\t],\n\tdatabase: 'db',\n\toptions: {\n\t\tw: 0,\n\t\treadPreference: 'secondary'\n\t}\n});\n\nconsole.log(connectionString); \n\n// prints \"mongodb://user:pass@host1:1111,host2:2222,host3:3333/db?w=0\u0026readPreference=secondary\"\n```\n\n\n## Install\n\nAs easy as running:\n\n```bash\nnpm install --save mongo-uri-builder\n```\n\nRequires Node.js 8+\n\n\n## Usage\n\nAs shown in the previous example the module exposes just a function that accepts an optional structured object as parameter. If no parameter is given the default `MongoDB://localhost` will be built.\n\n### Available options:\n\nAll the options are optional and the following example describes all the available ones:\n\n```javascript\n{\n\tusername: 'user', // the username\n\t// user: 'user', // this is alternative of username\n\tpassword: 'pass', // the password\n\thost: 'host1', // the main host (default: \"localhost\")\n\tport: 1111, // the main port\n\treplicas: [ // an array of replica databases\n\t\t{host: 'host2', port: 2222}, // every replica must define an host, the port is optional\n\t\t{host: 'host3', port: 3333}\n\t],\n\tdatabase: 'db', // the name of the database\n\toptions: { // an arbitrary object of connection options\n\t\tw: 0,\n\t\treadPreference: 'secondary'\n\t}\n}\n```\n\n## Contributing\n\nEveryone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by [opening an issue on GitHub](https://github.com/lmammino/mongo-uri-builder/issues).\n\nYou can also submit PRs as long as you adhere with the code standards and write tests for the proposed changes.\n\n### Code standard\n\n[XO](https://www.npmjs.com/package/xo) conventions and tools are used as code standard. You can easily check if your edits conforms the standard by running:\n\n```bash\nnpm run check-style\n```\n\n### Tests\n\n[Tape](https://www.npmjs.com/package/tape) is used as default test runner. You can easily run the tests by using:\n\n```bash\nnpm run tests\n```\n\n### Coverage\n\n[Covert](https://www.npmjs.com/package/covert) can be used to check tests coverage by running:\n\n```bash\nnpm run coverage\n```\n\n\n## License\n\nLicensed under [MIT License](https://github.com/lmammino/mongo-uri-builder/blob/master/LICENSE). © Luciano Mammino.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fmongo-uri-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmammino%2Fmongo-uri-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fmongo-uri-builder/lists"}