knowledge-kitchen

MongoDB - Setup

Database Design

  1. Overview
  2. Server Setup
  3. Client Setup
  4. Conclusions

Overview

The Plan

We will outline a few ways to gain access to a MongoDB server and use a MongDB client to issue commands to the database. Our discussion will include:

, locally using a Docker image

, and remotely using MongDB Atlas - a cloud-hosted solution.

, and using a driver with any of today’s popular programming languages

Server Setup

Choices of server

There are several easy ways to try out a MongoDB server.

MongoDB Atlas

Unless instructed otherwise, students are recommended to use MongoDB Atlas.

MongoDB Atlas (continued)

Unless your account already has a cluster, click to create and deploy one.

Create a cluster

MongoDB Atlas (continued again)

There are a few access controls you will be prompted to enter:

Once created, it may take a few minutes for the cluster to be deployed and ready to use.

MongoDB Atlas (continued once more)

Access control

MongoDB Atlas (continued yet again)

Once the cluster is created, the interface will provide you with Connection information, currently available by clicking the Connect button.

Docker container

Arguably the easist way to run a MongoDB server locally is to create a Docker container from the official MongoDB Docker image.

This is a good option if you only need the database to be accessible by you on your own machine.

To set up a server in this way, you must first…

Docker container (continued)

To launch a local MongoDB server in a Docker container:

A new container named mongodb_dockerhub will be created, running the latest version of MongoDB on the default port 27017 of the local machine. The command also configures a default database user account with the username admin and password secret.

Client setup

Choices of client

Regardless of which server you use, you must access it using a client. There are a few common MongoDB clients, including:

mongosh

Assuming you have installed it locally, use the MongoDB mongosh client to connect to the database server using your database’s connection string:

mongosh (continued again)

A database server can host many databases. Before performing any data-related operations, you must select the database you wish to use.

mongosh (continued once more)

Once connected, prove to yourself that you are logged into a Javascript command-line interface to MongoDB.

If so, you’re ready to start using your MongoDB database.

mongosh (continued for the last time)

To exit mongosh at any time, simply type exit and hit Enter.

mongoimport

The mongoimport command line utility is useful for importing bulk data from a text file into a MongoDB database collection. mongoimport supports JSON and CSV file formats.

Conclusions

Thank you. Good luck.