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.
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
- Docker (v20.10+) - Install Docker
- Docker Compose (v1.29+) - Usually included with Docker Desktop
Verify your installation:
docker --version
docker-compose --versioncd docker
docker-compose up -dThe MongoDB instance will be available at localhost:27017
docker exec -it mongodb_among mongosh -u admin -p passwordYou should see the MongoDB shell prompt >. Type exit to quit.
docker-compose downamong-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)
| Parameter | Value |
|---|---|
| Host | localhost |
| Port | 27017 |
| Username | admin |
| Password | password |
| Container Name | mongodb_among |
MongoDB Shell (mongosh):
mongosh mongodb://admin:password@localhost:27017Mongo 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')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 neededdocker exec mongodb_among mongoimport \
--username admin \
--password password \
--authenticationDatabase admin \
--db exercise \
--collection restaurants \
--file /data/db/../../../docs/restaurants.json \
--jsonArray# 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()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 } }
])docker-compose logs mongodb_among
docker-compose logs -f mongodb_among # Follow logsdocker-compose down
docker-compose up -d --build# View persisted data
ls -la docker/data/# Stop and remove volume (β οΈ deletes all data)
docker-compose down -v
# Restart fresh
docker-compose up -ddocker exec -it mongodb_among mongosh -u admin -p password
db.adminCommand("ping")- Query Reference: See
docs/TestoQuery.pdffor exercise instructions - Sample Data:
docs/restaurants.jsoncontains the restaurants dataset
Port 27017 already in use?
# Change the port in docker-compose.yml:
ports:
- "27018:27017" # Use 27018 insteadCannot 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
- 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 (
.gitignoreshould excludedocker/data/).
This setup supports learning:
- β MongoDB CRUD operations
- β Document data modeling
- β Aggregation pipelines
- β Indexing strategies
- β NoSQL vs SQL concepts
- β Container orchestration basics
For course-related questions, refer to the course materials or contact your instructor.
Last Updated: April 2026 | Course: New Generation Databases | University: UnivPM
