💾

Introduction to SQL and NoSQL Databases

Jul 17, 2024

Introduction to SQL and NoSQL Databases

Overview

  • Understanding the differences between SQL (relational) and NoSQL (non-relational) databases.
  • Explanation of SQL using the analogy of an Excel spreadsheet.
  • Introduction to NoSQL, particularly MongoDB.

SQL Databases

  • Structured Query Language (SQL)

    • Relational databases structured in tables with rows and columns.
    • Each row is a record; each column is a record field.
  • Challenges with SQL

    • Adding new fields requires new columns, leading to potential bloated tables.
    • Example: Multiple email addresses, physical addresses, and phone numbers needing separate columns.
    • Relational databases separate related data into distinct tables linked by IDs.
    • Data access across multiple tables requires JOIN operations.
    • Schemas
      • Define the structure or blueprint of data.
      • Are strict and inflexible, making changes cumbersome.
    • Scaling
      • Typically involves vertical scaling (upgrading to larger servers), which is costly.
    • SQL databases have been around since the 1970s, optimized for data deduplication due to expensive storage.
    • Complex structure, inflexibility, inefficiency, and high cost due to vertical scaling.

NoSQL Databases

  • Definition and Types

    • Term "NoSQL" can mean "Not SQL" or "Not Only SQL".
    • Various types of NoSQL databases: key-value, wide-column stores, graph, and document databases.
  • MongoDB

    • A document database.
    • Uses JSON (JavaScript Object Notation) to store data.
    • Structure
      • Documents contain key-value pairs.
      • Simple format: { "key": "value" }
      • Values can be strings, numbers, arrays, or other objects.
      • Example of user data in JSON format: { "_id": 1, "firstName": "John", "lastName": "Doe", "emails": ["[email protected]"], "addresses": ["123 Main St"], "phoneNumbers": ["123-456-7890"] }
    • Documents store all related data together, avoiding the need for JOINs.
    • Uses BSON (Binary JSON) for storage to support more data types.
    • Flexible schemas: Any type of data can be stored in any document, with no enforced structure by default.
    • Scalability
      • Supports horizontal scaling (adding more servers) instead of just vertical scaling, making it more cost-effective.

Key Terminology Differences

  • SQL vs NoSQL
    • Cluster = Cluster
    • Database = Database
    • Table (SQL) = Collection (NoSQL)
    • Row (SQL) = Document (NoSQL)
    • Column (SQL) = Field (NoSQL)

MongoDB Ecosystem

  • Self-hosted

    • Host MongoDB server on own hardware.
    • Requires self-management for server updates and maintenance.
    • Free to use open-source community server.
  • MongoDB Atlas

    • Fully managed, global cloud database service.
    • Deployable across AWS, Google Cloud, Azure.
    • Ensures availability, scalability, and compliance with data security and privacy standards.

MongoDB Tools

  • Compass

    • GUI for MongoDB, available on Linux, Mac, and Windows.
    • Allows visual data exploration, ad hoc queries, CRUD operations, and performance optimization.
  • MongoDB Realm

    • For building mobile apps with edge-to-cloud sync and back-end services.
    • Handles conflict resolution and networking code.
  • MongoDB Atlas Search

    • Full-text search capabilities, powered by Lucene.
    • Features fuzzy searching, autocomplete, filters, facets, and custom scoring.
  • MongoDB Charts

    • Data visualization tool integrated with MongoDB Cloud.
    • For real-time insights, business intelligence, and embedded analytics.
  • Atlas Online Archive

    • Tier data across managed databases and cloud storage, accessible via a single endpoint.
    • Archive historical data to save on storage costs.
  • Atlas Data Lake

    • Query and analyze data stored in AWS S3 and MongoDB Atlas.
    • Supports CSV and other formats.
    • Allows analysis without data movement or operational overhead.

Next Steps

  • Learn more about MongoDB Atlas by signing up for a free account.
  • Upcoming video: Creating the first Atlas cluster and loading sample data.