Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Among-DB

Copertina

MongoDB Docker MIT License

A MongoDB containerized learning environment for the New Generation Databases course at UnivPM. Designed to practice NoSQL concepts, aggregation pipelines, and database management in a isolated Docker environment.

🎯 Overview

This repository provides a fully containerized MongoDB instance pre-configured for coursework exercises. It includes sample datasets and is ready for immediate use without complex setup procedures.

Perfect for:

  • Learning NoSQL database concepts
  • Practicing MongoDB queries and aggregations
  • Understanding document-oriented data modeling
  • Running reproducible database exercises

πŸ“‹ Prerequisites

  • Docker (v20.10+) - Install Docker
  • Docker Compose (v1.29+) - Usually included with Docker Desktop

Verify your installation:

docker --version
docker-compose --version

πŸš€ Quick Start

1. Start the Database

cd docker
docker-compose up -d

The MongoDB instance will be available at localhost:27017

2. Verify Connection

docker exec -it mongodb_among mongosh -u admin -p password

You should see the MongoDB shell prompt >. Type exit to quit.

3. Stop the Database

docker-compose down

πŸ“ Project Structure

among-db/
β”œβ”€β”€ README.md                    # This file
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ docker-compose.yml       # MongoDB container configuration
β”‚   └── data/                    # MongoDB persistent data volume
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ TestoQuery.pdf           # Exercise instructions & query reference
β”‚   └── restaurants.json         # Sample dataset (restaurants collection)
└── scripts/                     # (Future: automation scripts)

πŸ—„οΈ Database Configuration

Parameter Value
Host localhost
Port 27017
Username admin
Password password
Container Name mongodb_among

Connection Strings

MongoDB Shell (mongosh):

mongosh mongodb://admin:password@localhost:27017

Mongo Compass URI:

mongodb://admin:password@localhost:27017

Node.js (Mongoose):

const uri = 'mongodb://admin:password@localhost:27017/exercise?authSource=admin';

Python (PyMongo):

from pymongo import MongoClient
client = MongoClient('mongodb://admin:password@localhost:27017/?authSource=admin')

πŸ’Ύ Loading Sample Data

Option 1: Using mongosh

docker exec -it mongodb_among mongosh -u admin -p password

# Inside the shell:
use exercise
db.restaurants.drop()
load('/data/db/../../../docs/restaurants.json')  # Adjust path as needed

Option 2: Using mongoimport

docker exec mongodb_among mongoimport \
  --username admin \
  --password password \
  --authenticationDatabase admin \
  --db exercise \
  --collection restaurants \
  --file /data/db/../../../docs/restaurants.json \
  --jsonArray

πŸ” Usage Examples

Connect and Explore

# Access the MongoDB shell
docker exec -it mongodb_among mongosh -u admin -p password

# List databases
show databases

# Switch to exercise database
use exercise

# List collections
show collections

# Query restaurants
db.restaurants.find().limit(5).pretty()

# Count documents
db.restaurants.countDocuments()

Common Operations

Find all restaurants:

db.restaurants.find({})

Find by cuisine type:

db.restaurants.find({ cuisine: "Italian" })

Find with aggregation:

db.restaurants.aggregate([
  { $group: { _id: "$cuisine", count: { $sum: 1 } } },
  { $sort: { count: -1 } }
])

πŸ› οΈ Development Tips

View Logs

docker-compose logs mongodb_among
docker-compose logs -f mongodb_among  # Follow logs

Rebuild the Container

docker-compose down
docker-compose up -d --build

Access Data Directly

# View persisted data
ls -la docker/data/

Reset the Database

# Stop and remove volume (⚠️ deletes all data)
docker-compose down -v

# Restart fresh
docker-compose up -d

Performance Check

docker exec -it mongodb_among mongosh -u admin -p password
db.adminCommand("ping")

πŸ“– Course Materials

  • Query Reference: See docs/TestoQuery.pdf for exercise instructions
  • Sample Data: docs/restaurants.json contains the restaurants dataset

βš™οΈ Troubleshooting

Port 27017 already in use?

# Change the port in docker-compose.yml:
ports:
  - "27018:27017"  # Use 27018 instead

Cannot connect to MongoDB?

  • Verify the container is running: docker ps
  • Check logs: docker-compose logs mongodb_among
  • Ensure port 27017 is not blocked by firewall

Connection refused?

  • Wait a few seconds for MongoDB to fully start
  • Try: docker-compose restart mongodb_among

πŸ“ Notes

  • Default credentials are set for learning purposes only. Change them for production use.
  • Data persists in docker/data/ even after stopping the container.
  • MongoDB data is not included in version control (.gitignore should exclude docker/data/).

πŸŽ“ Learning Objectives

This setup supports learning:

  • βœ… MongoDB CRUD operations
  • βœ… Document data modeling
  • βœ… Aggregation pipelines
  • βœ… Indexing strategies
  • βœ… NoSQL vs SQL concepts
  • βœ… Container orchestration basics

πŸ“§ Support

For course-related questions, refer to the course materials or contact your instructor.


Last Updated: April 2026 | Course: New Generation Databases | University: UnivPM

About

Containerized MongoDB environment, helpful to learn fundamentals of NoSQL DBs

Topics

Resources

Stars

Watchers

Forks

Contributors