{"id":18477820,"url":"https://github.com/dadi/api-mongodb","last_synced_at":"2025-04-08T15:31:40.615Z","repository":{"id":57105371,"uuid":"81696927","full_name":"dadi/api-mongodb","owner":"dadi","description":"A MongoDB adapter for DADI API","archived":false,"fork":false,"pushed_at":"2020-09-04T03:27:31.000Z","size":449,"stargazers_count":3,"open_issues_count":4,"forks_count":2,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2024-04-25T15:02:42.668Z","etag":null,"topics":["dadi","dadi-api","database","mongo","mongodb"],"latest_commit_sha":null,"homepage":"","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/dadi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-12T02:12:04.000Z","updated_at":"2020-08-18T10:43:17.000Z","dependencies_parsed_at":"2022-08-21T03:00:27.843Z","dependency_job_id":null,"html_url":"https://github.com/dadi/api-mongodb","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadi%2Fapi-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadi%2Fapi-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadi%2Fapi-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dadi%2Fapi-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dadi","download_url":"https://codeload.github.com/dadi/api-mongodb/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247871225,"owners_count":21010008,"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":["dadi","dadi-api","database","mongo","mongodb"],"created_at":"2024-11-06T12:06:17.664Z","updated_at":"2025-04-08T15:31:40.277Z","avatar_url":"https://github.com/dadi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API MongoDB Adapter\n\n[![npm version](https://badge.fury.io/js/%40dadi%2Fapi-mongodb.svg)](https://badge.fury.io/js/%40dadi%2Fapi-mongodb)\n[![Coverage Status](https://coveralls.io/repos/github/dadi/api-mongodb/badge.svg?branch=master)](https://coveralls.io/github/dadi/api-mongodb?branch=master)\n[![Build Status](https://travis-ci.org/dadi/api-mongodb.svg?branch=master)](https://travis-ci.org/dadi/api-mongodb)\n[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)\n\n## Requirements\n\n* [DADI API](https://www.npmjs.com/package/@dadi/api) Version 3.0.0 or greater\n* A running MongoDB server\n\n## Usage\n\nTo use this adapter with your DADI API installation, you'll need to add it to your API's dependencies:\n\n```bash\n$ cd my-api\n$ npm install @dadi/api-mongodb\n```\n\n## Tests\n\nTo run the test suite you'll need a MongoDB server running on localhost with the default port of 27017. If you've changed the default port, modify the test configuration file at `config/mongodb.test.json`. This file is created from `config/mongodb.test.json.sample` the first time the test suite is run.\n\nRun the tests:\n\n```bash\n$ git clone https://github.com/dadi/api-mongodb.git\n$ cd api-mongodb\n$ npm test\n```\n\n## Configuration\n\n### Configuration Files\n\nConfiguration settings are defined in JSON files within a `/config` directory at the root of your API application. DADI API uses a configuration file for the MongoDB connector that matches the environment you are running under.\n\nThe naming convention for MongoDB configuration files follows the format `mongodb.\u003cenvironment\u003e.json`\n\n#### Example\n\nAssuming that the entry point for your application is `main.js` and launching it with the following command, DADI API will attempt to load a MongoDB configuration file named `mongodb.production.js`.\n\n```sh\n$ NODE_ENV=production node main.js\n```\n### Application Anatomy\n\n```sh\nmy-api/\n  config/                     # contains environment-specific configuration properties\n    config.development.json   # main API configuration file, development environment\n    config.production.json\n    mongodb.development.json  # MongoDB configuration file, development environment\n    mongodb.production.json\n\n  main.js                     # the entry point of the app\n\n  package.json\n\n  workspace/\n    collections/              # collection schema files\n    endpoints/                # custom Javascript endpoints\n\n```\n\n### Configuration\n\nSpecifies the MongoDB database(s) to connect to.\n\n```json\n{\n  \"enableCollectionDatabases\": false,\n  \"databases\": [\n    {\n      \"id\": \"authdb\",\n      \"hosts\": \"127.0.0.1:27017\",\n      \"username\": \"johndoe\",\n      \"password\": \"topsecret\"\n    },\n    {\n      \"default\": true,\n      \"id\": \"secondary\",\n      \"hosts\": \"127.0.0.1:27018\"\n    }\n  ]\n}\n```\n\n#### Configuration Properties\n\n##### `enableCollectionDatabases`\n\nDetermines whether the database portion of the URL should dictate the actual MongoDB database to be used. When enabled, the request `GET /1.0/mydatabase/mycollection` would look for documents in a database with the ID `mydatabase`. If disabled, the default database (i.e. containing the property `default: true` in the configuration file) will be used.\n\n##### `databases`\n\nThe list of MongoDB databases to be used, as an array. Each database must be defined as an object with the following properties:\n\n###### `authDatabase`\n\nThe database to authenticate against when supplying a username and password.\n\n- _Format_: String\n- _Default_: `''`\n- _Environment variable_: `DB_{database}_AUTH_SOURCE`\n- _Required_: No\n\n###### `authMechanism`\n\nIf no authentication mechanism is specified or the mechanism DEFAULT is specified, the driver will attempt to authenticate using the SCRAM-SHA-1 authentication method if it is available on the MongoDB server. If the server does not support SCRAM-SHA-1 the driver will authenticate using MONGODB-CR.\n\n- _Format_: String\n- _Default_: `''`\n- _Environment variable_: `DB_{database}_AUTH_MECHANISM`\n- _Required_: No\n\n###### `default`\n\nWhether this database should be used as the default (main) database. When no database has the `default` flag, the first one in the array will be used as default.\n\n- _Format_: Boolean\n- _Default_: `false`\n- _Environment variable_: `DB_{database}_DEFAULT`\n- _Required_: No\n\n###### `hosts`\n\nComma-separated string of MongoDB hosts, including port (e.g. localhost,localhost:27018,localhost:27019).\n\n- _Format_: String\n- _Environment variable_: `DB_{database}_HOSTS`\n- _Required_: **Yes**\n\n\n###### `id`\n\nDatabase unique identifier.\n\n- _Format_: String\n- _Required_: **Yes**\n\n\n###### `maxPoolSize`\n\nThe maximum number of connections in the connection pool.\n\n- _Format_: Number\n- _Default_: `0`\n- _Environment variable_: `DB_{database}_MAX_POOL`\n- _Required_: No\n\n\n###### `password`\n\nThe access password, if one is needed.\n\n- _Format_: String\n- _Default_: `\"\"`\n- _Environment variable_: `DB_{database}_PASSWORD`\n- _Required_: No\n\n\n###### `readPreference`\n\nHow MongoDB routes read operations to the members of a replica set - see https://docs.mongodb.com/manual/reference/read-preference/.\n\n- _Format_: `\"primary\"`, `\"primaryPreferred\"`, `\"secondary\"`, `\"secondaryPreferred\"` or `\"nearest\"`\n- _Default_: `\"secondaryPreferred\"`\n- _Required_: No\n\n\n###### `replicaSet`\n\nThe name of the replica set to identify the hosts.\n\n- _Format_: String\n- _Required_: No\n\n\n###### `ssl`\n\nWhether to initiate the connection with TLS/SSL.\n\n- _Format_: Boolean\n- _Default_: `false`\n- _Required_: No\n\n\n###### `username`\n\nThe access username, if one is needed.\n\n- _Format_: String\n- _Default_: `\"\"`\n- _Environment variable_: `DB_{database}_USERNAME`\n- _Required_: No\n\n## Licence\n\nDADI is a data centric development and delivery stack, built specifically in support of the principles of API first and COPE.\n\nCopyright notice\u003cbr /\u003e\n(C) 2019 DADI+ Limited \u003csupport@dadi.cloud\u003e\u003cbr /\u003e\nAll rights reserved\n\nThis product is part of DADI.\u003cbr /\u003e\nDADI is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version (\"the GPL\").\n\n**If you wish to use DADI outside the scope of the GPL, please\ncontact us at info@dadi.co for details of alternative licence\narrangements.**\n\n**This product may be distributed alongside other components\navailable under different licences (which may not be GPL). See\nthose components themselves, or the documentation accompanying\nthem, to determine what licences are applicable.**\n\nDADI is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nThe GNU General Public License (GPL) is available at\nhttp://www.gnu.org/licenses/gpl-3.0.en.html.\u003cbr /\u003e\nA copy can be found in the file GPL.md distributed with\nthese files.\n\nThis copyright notice MUST APPEAR in all copies of the product!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdadi%2Fapi-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdadi%2Fapi-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdadi%2Fapi-mongodb/lists"}