This blog post explores the process of testing a MongoDB NoSQL database using, a robust Continuous Integration/Continuous Deployment (CI/CD) platform. We'll explore each step, from setting up your environment to analyzing test results and providing comprehensive tutorials for developers and users.


  • A GitHub repository with your MongoDB-based application.
  • An account on
  • Basic understanding of YAML and MongoDB.

Set up the EC2 Workflow Infrastructure

The AWS EKS EC2 ASG Auto scaling Workflow is open source on GitHub, and you can install it by cloning the repository.

git clone [email protected]:workflows-sh/aws-eks-ec2-asg-cdk.git

cd aws-eks-ec2-asg-cdk

Create Secret for your Workflow from Settings

Create your secrets in your dashboard by selecting Settings and Secrets. Secrets are encrypted environment variables that utilizes within your workflow to build and run your application and deployments.

You will create four secrets:

  • To create your AWS SECRET KEY AND ACCESS KEY. Log into your AWS Account, select the Identity and Access Management (IAM) dashboard, create a new user, copy the Access Key ID and Secret access key, and paste it into your secret dashboard on
  • Your AWS ACCOUNT NUMBER can be obtained from your User ID on the top right corner of your AWS Console.

Generate GitHub Token

Generate your GITHUB_TOKEN from Github by going to Settings → Developer settings → Personal access tokens → Generate new token on your Github profile.

  • Back in your Secrets dashboard, create your secret key/value pairs.

Back in your AWS EKS EC2 ASG workflow, build and set up your infrastructure using the ops run -b . command. This will provision your AWS-EKS EC2 ASG stacks using Cloud Formation.


View EC2 instances on AWS

Back in your AWS console, you can see your EC2 instances running. The AWS EC2 Workflow creates four instances for you:

  • dev-aws-eks-ec2-asg/dev-aws-eks-ec2-asg-asg
  • dev-aws-eks-ec2-asg/dev-aws-eks-ec2-asg-asg
  • dev-aws-eks-ec2-asg/dev-aws-eks-ec2-asg-asg

You can use any of the EC2 instance(s) to deploy your MongoDB NoSQL database.

Connect to Your EC2 Instance

Use SSH to connect to your instance. For example:

ssh -i /path/to/your-key.pem ec2-user@your-ec2-instance-public-ip

Install MongoDB

Update Your Package Database (if using Ubuntu or Debian):

sudo apt-get update

Install MongoDB (For Ubuntu/Debian)

sudo apt-get install -y mongodb

For Amazon Linux/CentOS:

sudo yum install -y mongodb-org

Start MongoDB and Enable it to Start on Boot

sudo systemctl start mongod

sudo systemctl enable mongod

Configure MongoDB

  • Edit the MongoDB config file (/etc/mongod.conf) to set up bind IP and other configurations.

  • Restart MongoDB to apply the changes:
sudo systemctl restart mongod

Test MongoDB Installation

Verify that MongoDB is running correctly

mongo --eval 'db.runCommand({ connectionStatus: 1 })'

Configure Your Pipeline

The heart of integration lies in the ops.yaml file. This file contains instructions for the platform to set up your environment, run tests, and report results. A typical configuration might look like this:

version: "1"
- name: mongodb-test-pipeline-ec2:0.1.0
description: Build and test MongoDB with Node.js application on EC2
- DEBIAN_FRONTEND=noninteractive
- AWS_REGION=us-west-1
- NODE_VERSION=14.x  # Specify your Node.js version
- EC2_SSH_PRIVATE_KEY  # SSH key for EC2 access
- EC2_INSTANCE_IP      # Public IP of the EC2 instance
- "github:<your-github-repo-path>:pull_request.merged"
- "github:<your-github-repo-path>:pull_request.opened"
- "github:<your-github-repo-path>:pull_request.synchronize"
- name: mongodb-nodejs-test-job-ec2
description: MongoDB with Node.js test job on EC2
- git
- sshpass
- sshpass -p $EC2_INSTANCE_PASSWORD ssh -o StrictHostKeyChecking=no ec2-user@$EC2_INSTANCE_IP "sudo yum update -y"
- sshpass -p $EC2_INSTANCE_PASSWORD ssh ec2-user@$EC2_INSTANCE_IP "curl -o- | bash"
- sshpass -p $EC2_INSTANCE_PASSWORD ssh ec2-user@$EC2_INSTANCE_IP "nvm install $NODE_VERSION"
- sshpass -p $EC2_INSTANCE_PASSWORD ssh ec2-user@$EC2_INSTANCE_IP "sudo yum install -y mongodb-org"
- sshpass -p $EC2_INSTANCE_PASSWORD ssh ec2-user@$EC2_INSTANCE_IP "sudo systemctl start mongod && sudo systemctl enable mongod"
- sshpass -p $EC2_INSTANCE_PASSWORD ssh ec2-user@$EC2_INSTANCE_IP "git clone https://oauth2:[email protected]/$ORG/$REPO"
- sshpass -p $EC2_INSTANCE_PASSWORD ssh ec2-user@$EC2_INSTANCE_IP "cd $REPO && npm install && npm test"
- name: mongodb-nodejs-service-ec2:0.1.0
description: MongoDB with Node.js service on EC2
run: node /ops/index.js
port: ['8080:8080']
sdk: off
domain: ""
- PORT=8080
- "github:<your-github-repo-path>:pull_request.merged"
- "github:<your-github-repo-path>:pull_request.opened"
- "github:<your-github-repo-path>:pull_request.synchronize"
- build
- publish
- start

Crafting MongoDB Tests

Testing a MongoDB database involves checking connection stability, data manipulation accuracy, and response to various queries. In a Node.js environment, we configured above using the ops.yaml file a test file can look like:

const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
describe('MongoDB Operations', () => {
it('should perform a sample operation', async () => {
const uri = "mongodb://localhost:27017";
const client = new MongoClient(uri);
try {
await client.connect();
// Your test logic here
} catch (e) {"MongoDB operation failed");
} finally {
await client.close();

Pushing Code and Triggering Tests

With your tests in place, commit and push these changes to your repository. This action will trigger the pipeline, where the defined steps in your ops.yml  file will execute. orchestrates the entire process, from setting up the workflow and deploying your MongoDB database. You can also trigger the pipeline when you open a pull request.


Testing MongoDB with makes the process of ensuring database reliability and performance in your applications better and more reliable. By following this guide, you can set up an automated testing pipeline that aligns with modern deployment workflow practices, enhancing your software development lifecycle.

Ready to unlock the power of for your team? Schedule your consultation now with one of our experts today!