Working with MongoDB

Hands-On Lab

 

Photo of Michael McClaren

Michael McClaren

Linux Training Architect I in Content

Length

01:00:00

Difficulty

Intermediate

There are often times that you will be called upon in your journey to assist in the testing of a new technology. In this hands-on lab, you will be installing MongoDB. Once it has been installed, you will be bulk inserting data to be used by your Dev team for testing.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with MongoDB

Introduction

There are often times that you will be called upon in your journey to assist in the testing of a new technology. In this hands-on lab, you will be installing MongoDB. Once it has been installed, you will be bulk inserting data to be used by your Dev team for testing.

Solution

  1. Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

    ssh cloud_user@PUBLIC_IP_ADDRESS
  2. Become the root user:

    sudo su

Install MongoDB version 4.0

  1. Add the YUM repository for the repo:

    cat << EOF > /etc/yum.repos.d/mongodb-org-4.0.repo
    [mongodb-org-4.0] 
    name=MongoDB Repository 
    baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/ 
    gpgcheck=1 
    enabled=1 
    gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc 
    EOF
  2. Install and start MongoDB

    yum install -y mongodb-org
    service mongod start

Insert the test data located in /home/cloud_user/data/cities.csv

  1. Exit the root user session:

    exit
  2. Run the mongoimport command:

    mongoimport -d cities -c cityinfo --type CSV --file /home/cloud_user/data/cities.csv --headerline

Validate that the data has the required entries

  1. This is done from the mongo shell:

    mongo
    use cities
    db.cityinfo.find({State:"GA"})

    This should return 4 records.

  2. Exit the mongo shell.

    exit
  3. Exit the server.

    exit

Conclusion

Congratulations — you've completed this hands-on lab!