MongoDB - OrdinBeta/IT-Landscape GitHub Wiki

MongoDB

Table of Contents

What is MongoDB?

MongoDB is a NoSQL database that uses a document-oriented data model. It stores data in flexible, JSON-like documents, which allows for easy scalability and the ability to handle unstructured data. MongoDB is designed for high availability and performance, making it a popular choice for modern web applications.

How to install MongoDB (using Docker)?

Installing MongoDB using Docker is actually pretty simple.

Step 1: Create a docker-compose.yml file

Add the below services to your docker-compose.yml file:

services:
  mongo:
    image: mongo
    restart: always
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: test

  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8082:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: test
      ME_CONFIG_MONGODB_URL: mongodb://root:test@mongo:27017/
      ME_CONFIG_BASICAUTH: false
    depends_on:
      - mongo

Step 2: docker-compose up -d

(Step 3: Access MongoDB using MongoDB Express)

Visit http://localhost:8082 in your web browser to access the MongoDB Express interface.

Step 4: Download mongosh

You can download the MongoDB shell (mongosh) from their website. Or for your convenience, I have added a link to their windows msi. Run the installer, you can leave all the settings as they are.

Step 5: Connect to MongoDB using mongosh

Open a new terminal and run the following command below. If mongosh is not recognized, you can try restarting visual studio code. If that doesn't work, you can try restarting your computer.

mongosh "mongodb://root:test@localhost:27017/"

You should see a prompt indicating that you are connected to the MongoDB server. You can clear the terminal by typing cls.

How to use MongoDB?

Sources