Skip to content

hackatbrown/database-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Database Starter Kit


Just Want It Working in 20 Minutes? Do This:

Recommended: MongoDB Atlas (free, no installation, works everywhere)

  1. Go to mongodb.com/cloud/atlas and click "Try Free"
  2. Create an account (use Google/GitHub for speed)
  3. Choose the FREE tier (M0 Sandbox) when prompted
  4. Select any cloud provider & region (pick one close to you)
  5. Create a database user - username and password (save these!)
  6. Add your IP address to the access list (click "Add My Current IP Address")
  7. Click "Connect" → "Connect your application" → Copy the connection string
  8. Replace <password> in the connection string with your actual password
  9. Install the driver in your project:
    • Node.js: npm install mongodb
    • Python: pip install pymongo
  10. Test it works - paste this in your code:
    // Node.js
    const { MongoClient } = require('mongodb');
    const client = new MongoClient('your-connection-string-here');
    await client.connect();
    console.log('Connected!');

That's it! You now have a working database. For more details, see the MongoDB Starter Kit.


Welcome to Hack@Brown's Database Starter Kit!

Choosing the right database is one of the most important decisions you'll make during a hackathon. The database you select will shape how you structure your data, how quickly you can iterate, and how well your application scales. This starter kit is designed to help you navigate that choice with confidence.

This repository provides comprehensive guides for three widely-used database systems: MongoDB, PostgreSQL, and MySQL. Each has its strengths and ideal use cases. Whether you're building a social platform with rapidly evolving data models, an e-commerce application requiring complex transactions, or a content management system with flexible schemas, one of these databases will fit your needs.

The guides below will walk you through setup, basic operations, and best practices for each database. Take a few minutes to review the comparison table and explore the starter kit that matches your project requirements.

Documentation Guide

This starter kit includes detailed documentation to help you get started:

  • setup_guide.md - Complete setup instructions for all three databases (MongoDB, PostgreSQL, and MySQL). Start here to get your database running with step-by-step instructions for both cloud and local setups.

  • walkthrough.md - A beginner-friendly, detailed walkthrough that explains each step in depth. Perfect if you're new to databases or want to understand what's happening behind the scenes.

Quick Start: Choose your database below, then follow the setup_guide.md for installation instructions.

Database Comparison

Feature MongoDB PostgreSQL MySQL
Type NoSQL (Document) SQL (Relational) SQL (Relational)
Best For Flexible schemas, rapid prototyping, unstructured data Complex queries, data integrity, ACID compliance Web applications, read-heavy workloads
Schema Flexibility Very flexible, schema-less Structured, requires migrations Structured, requires migrations
Query Language MongoDB Query Language (MQL) SQL with advanced features Standard SQL
Scaling Horizontal (sharding built-in) Primarily vertical Primarily vertical
Transactions Supported (recent versions) Full ACID compliance Full ACID compliance
Joins Limited ($lookup) Excellent, complex joins Good, standard joins
Data Model Document-oriented (JSON-like) Relational tables Relational tables
Learning Curve Moderate (data modeling approach) Steeper (many features) Gentle (familiar SQL)
Performance Fast reads/writes, horizontal scaling Excellent for complex queries Excellent for read-heavy loads
Advanced Features Aggregation pipeline, geospatial JSON/JSONB, full-text search, window functions, CTEs Good standard features
Community & Ecosystem Large, JavaScript-focused Very large, enterprise adoption Huge, web development focus
Ideal Use Cases User profiles, content management, catalogs Analytics, complex relationships, financial data Traditional web apps, content sites

Starter Kit Links

Decision Flowchart

Start Here
    |
    ├─ Is your data structure still evolving?
    │  └─ YES → MongoDB
    │  └─ NO → Continue
    |
    ├─ Do you need complex queries with multiple joins?
    │  └─ YES → PostgreSQL or MySQL
    │  └─ NO → MongoDB
    |
    ├─ Do you need advanced features (window functions, CTEs, etc.)?
    │  └─ YES → PostgreSQL
    │  └─ NO → Continue
    |
    ├─ Are you building a traditional web application?
    │  └─ YES → MySQL
    │  └─ NO → Continue
    |
    ├─ Do you need the most flexible schema?
    │  └─ YES → MongoDB
    │  └─ NO → PostgreSQL or MySQL
    |
    └─ When in doubt: Start with PostgreSQL (most versatile)

Common Project Scenarios

Social Media Platform

Recommendation: MongoDB or PostgreSQL

  • MongoDB: Great for user profiles, posts, comments (document model)
  • PostgreSQL: Better if you need complex social graphs and relationships

E-commerce Store

Recommendation: PostgreSQL or MySQL

  • Both excellent for product catalogs, orders, inventory
  • PostgreSQL if you need advanced search and filtering
  • MySQL for simpler implementations

Real-time Dashboard

Recommendation: PostgreSQL or MongoDB

  • PostgreSQL: Best for complex aggregations and analytics
  • MongoDB: Good for rapidly changing metrics and flexible schema

Content Management System

Recommendation: MongoDB or MySQL

  • MongoDB: Flexible content types, easy to add new fields
  • MySQL: Traditional approach, proven pattern

API Backend

Recommendation: Any (depends on data structure)

  • MongoDB: Fast prototyping, flexible responses
  • PostgreSQL: Complex business logic, strict data validation
  • MySQL: Simple CRUD operations, standard API

Quick Setup Recommendations

Fastest Setup:

  1. MongoDB: MongoDB Atlas (free tier, no installation)
  2. PostgreSQL: Supabase (includes auth, storage)
  3. MySQL: PlanetScale (serverless, no configuration)

Local Docker Setup:

# MongoDB
docker run -d -p 27017:27017 --name mongo mongo:latest

# PostgreSQL
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=pass --name postgres postgres:15

# MySQL
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pass --name mysql mysql:8.0

Common Mistakes to Avoid

  1. Over-engineering: Start simple, add complexity only when needed
  2. No indexes: Add indexes on foreign keys and frequently queried fields
  3. Security: Never commit database credentials to git
  4. No backups: Export your data periodically during development

Database-Specific:

Environment Variables

Keep your credentials safe! Use environment variables:

# .env file (add to .gitignore!)
DB_TYPE=mongodb  # or postgresql, mysql
DB_HOST=localhost
DB_PORT=27017  # 5432 for postgres, 3306 for mysql
DB_NAME=hackatbrown
DB_USER=username
DB_PASSWORD=password

# For MongoDB Atlas, PostgreSQL cloud, etc.
DATABASE_URL=mongodb+srv://user:[email protected]/hackatbrown

Load in your app:

  • Node.js: npm install dotenv then require('dotenv').config()
  • Python: pip install python-dotenv then from dotenv import load_dotenv
  • Java: Use Spring Boot's application.properties

Testing Your Database

Before building your full application, test your database:

MongoDB

// test-connection.js
const { MongoClient } = require('mongodb');
MongoClient.connect(process.env.DATABASE_URL)
  .then(client => {
    console.log('Connected to MongoDB');
    client.close();
  })
  .catch(err => console.error('Connection failed:', err));

PostgreSQL / MySQL

// test-connection.js
const { Client } = require('pg'); // or 'mysql2'
const client = new Client({ connectionString: process.env.DATABASE_URL });
client.connect()
  .then(() => {
    console.log('Connected to database');
    client.end();
  })
  .catch(err => console.error('Connection failed:', err));

Help & Support

During the hackathon:

  1. Check the relevant starter pack markdown file
  2. Search Stack Overflow (most common issues are documented)
  3. Check official documentation
  4. Ask mentors or teammates
  5. Database-specific communities (Discord, Slack, Reddit)

Official Documentation:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published