{"id":17267855,"url":"https://github.com/supercharge/mongodb-github-action","last_synced_at":"2025-05-14T08:09:42.355Z","repository":{"id":41090770,"uuid":"228638978","full_name":"supercharge/mongodb-github-action","owner":"supercharge","description":"Use MongoDB in GitHub Actions","archived":false,"fork":false,"pushed_at":"2025-01-05T12:33:13.000Z","size":195,"stargazers_count":241,"open_issues_count":5,"forks_count":51,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-07T01:01:45.006Z","etag":null,"topics":["github-actions","github-actions-docker","mongodb","mongodb-server","supercharge"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/supercharge.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-17T14:52:06.000Z","updated_at":"2025-04-29T00:16:28.000Z","dependencies_parsed_at":"2024-04-08T09:27:30.990Z","dependency_job_id":"447ab23a-aa9b-465a-9623-425d6f49c284","html_url":"https://github.com/supercharge/mongodb-github-action","commit_stats":{"total_commits":238,"total_committers":12,"mean_commits":"19.833333333333332","dds":0.1386554621848739,"last_synced_commit":"90004df786821b6308fb02299e5835d0dae05d0d"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fmongodb-github-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fmongodb-github-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fmongodb-github-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fmongodb-github-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supercharge","download_url":"https://codeload.github.com/supercharge/mongodb-github-action/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101558,"owners_count":22014908,"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":["github-actions","github-actions-docker","mongodb","mongodb-server","supercharge"],"created_at":"2024-10-15T08:11:47.742Z","updated_at":"2025-05-14T08:09:37.346Z","avatar_url":"https://github.com/supercharge.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\r\n  \u003ca href=\"https://superchargejs.com\"\u003e\r\n    \u003cimg width=\"471\" style=\"max-width:100%;\" src=\"https://superchargejs.com/images/supercharge-text.svg\" /\u003e\r\n  \u003c/a\u003e\r\n  \u003cbr/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ch3\u003eMongoDB in GitHub Actions\u003c/h3\u003e\r\n  \u003c/p\u003e\r\n  \u003cp\u003e\r\n    Start a MongoDB server in your GitHub Actions.\r\n  \u003c/p\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ca href=\"#usage\"\u003e\u003cstrong\u003eUsage\u003c/strong\u003e\u003c/a\u003e\r\n  \u003c/p\u003e\r\n  \u003cbr/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003cem\u003eFollow \u003ca href=\"http://twitter.com/marcuspoehls\"\u003e@marcuspoehls\u003c/a\u003e and \u003ca href=\"http://twitter.com/superchargejs\"\u003e@superchargejs\u003c/a\u003e for updates!\u003c/em\u003e\r\n  \u003c/p\u003e\r\n\u003c/div\u003e\r\n\r\n---\r\n\r\n\r\n## Introduction\r\nThis GitHub Action starts a MongoDB server or MongoDB replica set. By default, the MongoDB server is available on the default port `27017`. You can configure a custom port using the `mongodb-port` input. The examples show how to use a custom port.\r\n\r\nThe MongoDB version must be specified using the `mongodb-version` input. The used version must exist in the published [`mongo` Docker hub tags](https://hub.docker.com/_/mongo?tab=tags). Default value is `latest`, other popular choices are `6.0`, `7.0` or even release candidates `8.0.0-rc4`.\r\n\r\nThis is useful when running tests against a MongoDB database.\r\n\r\n\r\n## Usage\r\nA code example says more than a 1000 words. Here’s an exemplary GitHub Action using a MongoDB server in different versions to test a Node.js app:\r\n\r\n```yaml\r\nname: Run tests\r\n\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    strategy:\r\n      matrix:\r\n        node-version: [20.x, 22.x]\r\n        mongodb-version: ['6.0', '7.0', '8.0']\r\n\r\n    steps:\r\n    - name: Git checkout\r\n      uses: actions/checkout@v4\r\n\r\n    - name: Use Node.js ${{ matrix.node-version }}\r\n      uses: actions/setup-node@v4\r\n      with:\r\n        node-version: ${{ matrix.node-version }}\r\n\r\n    - name: Start MongoDB\r\n      uses: supercharge/mongodb-github-action@1.12.0\r\n      with:\r\n        mongodb-version: ${{ matrix.mongodb-version }}\r\n\r\n    - run: npm install\r\n\r\n    - run: npm test\r\n      env:\r\n        CI: true\r\n```\r\n\r\n\r\n### Using a Custom MongoDB Port\r\nYou can start the MongoDB instance on a custom port. Use the `mongodb-port: 12345` input to configure port `12345` for MongoDB. Replace `12345` with the port you want to use in your test runs.\r\n\r\nThe following example starts a MongoDB server on port `42069`:\r\n\r\n```yaml\r\nname: Run tests\r\n\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    strategy:\r\n      matrix:\r\n        node-version: [20.x, 22.x]\r\n        mongodb-version: ['6.0', '7.0', '8.0']\r\n\r\n    steps:\r\n    - name: Git checkout\r\n      uses: actions/checkout@v4\r\n\r\n    - name: Use Node.js ${{ matrix.node-version }}\r\n      uses: actions/setup-node@v4\r\n      with:\r\n        node-version: ${{ matrix.node-version }}\r\n\r\n    - name: Start MongoDB\r\n      uses: supercharge/mongodb-github-action@1.12.0\r\n      with:\r\n        mongodb-version: ${{ matrix.mongodb-version }}\r\n        mongodb-replica-set: test-rs\r\n        mongodb-port: 42069\r\n\r\n    - name: Install dependencies\r\n      run: npm install\r\n\r\n    - name: Run tests\r\n      run: npm test\r\n      env:\r\n        CI: true\r\n```\r\n\r\n\r\n### With a Replica Set (MongoDB `--replSet` Flag)\r\nYou can run your tests against a MongoDB replica set by adding the `mongodb-replica-set: your-replicate-set-name` input in your action’s workflow. The value for `mongodb-replica-set` defines the name of your replica set. Replace `your-replicate-set-name` with the replica set name you want to use in your tests.\r\n\r\nThe following example uses the replica set name `test-rs`:\r\n\r\n```yaml\r\nname: Run tests\r\n\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    strategy:\r\n      matrix:\r\n        node-version: [20.x, 22.x]\r\n        mongodb-version: ['6.0', '7.0', '8.0']\r\n\r\n    steps:\r\n    - name: Git checkout\r\n      uses: actions/checkout@v4\r\n\r\n    - name: Use Node.js ${{ matrix.node-version }}\r\n      uses: actions/setup-node@v4\r\n      with:\r\n        node-version: ${{ matrix.node-version }}\r\n\r\n    - name: Start MongoDB\r\n      uses: supercharge/mongodb-github-action@1.12.0\r\n      with:\r\n        mongodb-version: ${{ matrix.mongodb-version }}\r\n        mongodb-replica-set: test-rs\r\n        mongodb-port: 42069\r\n\r\n    - name: Install dependencies\r\n      run: npm install\r\n\r\n    - name: Run tests\r\n      run: npm test\r\n      env:\r\n        CI: true\r\n```\r\n\r\n\r\n### With Authentication (MongoDB `--auth` Flag)\r\nSetting the `mongodb-username` and `mongodb-password` inputs. As per the [Dockerhub documentation](https://hub.docker.com/_/mongo), this automatically creates an admin user and enables `--auth` mode.\r\n\r\nThe following example uses the username `supercharge`, password `secret` and also sets an initial `supercharge` database:\r\n\r\n```yaml\r\nname: Run tests with authentication\r\n\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    strategy:\r\n      matrix:\r\n        node-version: [20.x, 22.x]\r\n        mongodb-version: ['6.0', '7.0', '8.0']\r\n\r\n    steps:\r\n    - name: Git checkout\r\n      uses: actions/checkout@v4\r\n\r\n    - name: Use Node.js ${{ matrix.node-version }}\r\n      uses: actions/setup-node@v4\r\n      with:\r\n        node-version: ${{ matrix.node-version }}\r\n\r\n    - name: Start MongoDB\r\n      uses: supercharge/mongodb-github-action@1.12.0\r\n      with:\r\n        mongodb-version: ${{ matrix.mongodb-version }}\r\n        mongodb-username: supercharge\r\n        mongodb-password: secret\r\n        mongodb-db: supercharge\r\n\r\n    - name: Install dependencies\r\n      run: npm install\r\n\r\n    - name: Run tests\r\n      run: npm test\r\n      env:\r\n        CI: true\r\n```\r\n\r\n### With Custom Container Name\r\nThe container name of the created MongoDB instance can be configured using the `mongodb-container-name` input\r\n\r\nThe following example will parameterize the MongoDB container name based on the `node-version` and `mongodb-version` being used from the matrix:\r\n\r\n```yaml\r\nname: Run with Custom Container Names\r\n\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    strategy:\r\n      matrix:\r\n        node-version: [20.x, 22.x]\r\n        mongodb-version: ['6.0', '7.0', '8.0']\r\n\r\n    steps:\r\n    - name: Git checkout\r\n      uses: actions/checkout@v4\r\n\r\n    - name: Use Node.js ${{ matrix.node-version }}\r\n      uses: actions/setup-node@v4\r\n      with:\r\n        node-version: ${{ matrix.node-version }}\r\n\r\n    - name: Start MongoDB\r\n      uses: supercharge/mongodb-github-action@1.12.0\r\n      with:\r\n        mongodb-version: ${{ matrix.mongodb-version }}\r\n        mongodb-container-name: mongodb-${{ matrix.node-version }}-${{ matrix.mongodb-version }}\r\n\r\n    - name: Install dependencies\r\n      run: npm install\r\n\r\n    - name: Run tests\r\n      run: npm test\r\n      env:\r\n        CI: true\r\n```\r\n\r\n**Caveat:** due to [this issue](https://github.com/docker-library/mongo/issues/211), you **cannot enable user creation AND replica sets** initially. Therefore, if you use this action to setup a replica set, please create your users through a separate script.\r\n\r\n### Using a Custom Mongo Image\r\nYou can utilize an alternative MongoDB docker image using the `mongodb-image` input:\r\n\r\n\r\n```yaml\r\n    - name: Start MongoDB\r\n      uses: supercharge/mongodb-github-action@1.12.0\r\n      with:\r\n        # Here we are using an image from Amazon's ECR rather than the default image from Docker Hub\r\n        mongodb-image: 'public.ecr.aws/docker/library/mongo'\r\n        mongodb-version: ${{ matrix.mongodb-version }}\r\n```\r\n\r\n## License\r\nMIT © [Supercharge](https://superchargejs.com)\r\n\r\n---\r\n\r\n\u003e [superchargejs.com](https://superchargejs.com) \u0026nbsp;\u0026middot;\u0026nbsp;\r\n\u003e GitHub [@supercharge](https://github.com/supercharge) \u0026nbsp;\u0026middot;\u0026nbsp;\r\n\u003e Twitter [@superchargejs](https://twitter.com/superchargejs)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercharge%2Fmongodb-github-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupercharge%2Fmongodb-github-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercharge%2Fmongodb-github-action/lists"}