DbSchema Database Designer

MySQL vs MongoDB - Visual Design with Real Data Models



MySQL Diagram with DbSchema

When you’re starting learning databases, one of the first questions is: What are the differences between MySQL and MongoDB? They’re both interesting, but built for different purposes.

  • MySQL is structured, relational, and based on SQL.
  • MongoDB is flexible, document-based, and schema-less by default.

To really understand the difference, it helps to model something familiar, like how you store data in countries and cities.

Let’s see how you can design this model in both MySQL and MongoDB, and how you can do it visually - using the DbSchema tool.

DbSchema is not a database itself. It’s a visual tool that connects to your MySQL or MongoDB server and works directly with your database. Once connected, it shows you the real structure of your data - the tables or collections, the columns or fields, and even the relationships between them. You can explore the data, edit the schema, and understand your database more clearly, all in one place.

Key Differences: MySQL Tables vs MongoDB Documents

Feature MySQL MongoDB
Data Format Tables (rows and columns) Documents (JSON-like)
Schema Fixed and strict Flexible (optional validation)
Relationships Foreign keys Embedded or referenced
Query Language SQL MongoDB Query Language
Best For Structured data (e.g., bank accounts) Flexible data (e.g., user profiles)

Relational Modeling: MySQL Example

In MySQL, you define the structure first: the tables and columns, and then insert the data to match that structure.
Relationships are defined using foreign keys.

Schema Design for Countries and Cities

We’ll define:

  • A Countries table: each row is a country.
  • A Cities table: each city belongs to a country via country_id.

SQL Example

CREATE TABLE Countries (
id INT PRIMARY KEY,
name VARCHAR(200),
population INT
);

CREATE TABLE Cities (
id INT PRIMARY KEY,
name VARCHAR(200),
population INT,
country_id INT,
FOREIGN KEY (country_id) REFERENCES Countries(id)
);

This structure allows you to:

  • Normalize your data. (Learn more about this here)
  • Link each city to its country.
  • Enforce data integrity using foreign keys.

When you create a table using code or the command line, it works - but you can’t actually see its structure. Most developers use tools like MySQL Shell or MongoDB Shell, which show data, not design.

In DbSchema

Method I:

With DbSchema, you get a visual diagram of your tables, so you can see how everything is built and connected.

    1. Write the code in the SQL Editor.
    1. See the table created in a visual diagram.

Create two tables in MySQL

Method II:

If you’re not a developer, and you don’t know SQL Code, don’t worry! Instead of writing SQL, you can:

  • Add two tables visually.
  • Define columns using dropdowns for types.
  • Draw a line between Cities.country_id and Countries.id to create a foreign key.
  • DbSchema automatically generates the SQL script in the background and can deploy it to your database.

Document Modeling: MongoDB Example

MongoDB stores data in collections of documents, JSON-like objects that can contain nested structures such as arrays and objects.

In MongoDB, you insert documents that already contain data, and their shape defines the structure of the database.

When modeling countries and cities in MongoDB, you have two options:

Method I: Embedded Documents

Cities are stored inside each country document.

db.countries.insertOne({
"_id": 1,
"name": "France",
"population": 67000000,
"cities": [
{ "name": "Paris", "population": 2148000 },
{ "name": "Lyon", "population": 515695 }
]
})

This method is useful when:

  • Cities are always accessed together with their country.
  • You don’t need to query cities on their own.
  • You prefer a single document with all related data grouped.

Method II: Referenced Collections

Countries and cities are stored in separate collections, and cities reference the country via country_id.

db.countries.insertOne({{
"_id": 1,
"name": "France",
"population": 67000000
})

db.cities.insertOne({
{
"_id": 101,
"name": "Paris",
"population": 2148000,
"country_id": 1
})

This method is better when:

  • Cities are large or updated frequently.
  • You want to query or manage cities independently.
  • You want to avoid document size limitations.

In DbSchema

Method I:

With DbSchema, you get a visual diagram of your collections, so you can see how everything is built and connected.

    1. Write the code in the Mongo Query.
    1. See the collection created in a visual diagram.

Create a collection in MongoDB

Method II:

If you’re not a developer and don’t know MongoDB Shell or code, no problem! You can build everything visually in DbSchema:

  • Create a Countries collection using the diagram editor.
  • Add fields like name, population, or even an array of embedded cities.
  • Or create a separate Cities collection and link it to Countries using a country_id reference field.
  • Define field types, add indexes, or set up validation rules - all without writing any JSON or code.

Note: In MongoDB, you don’t have to define a schema up front, but you can enforce structure using validation rules.
Read more about schema validation in this article.

Why Use a Visual Tool Like DbSchema?

If you want to learn more about how to work with MySQL or MongoDB, you can read this articles.

  • Design visually - Create tables or collections just by clicking and dragging. No need to write code.
  • See the structure clearly - The diagram shows how everything is connected, which makes it easier to understand.
  • Skip the code - DbSchema writes the SQL or JSON for you, so you can focus on the logic, not the syntax.
  • Work as a team - Built-in Git support helps you keep track of changes and collaborate safely.
  • Create clean documentation - Export your diagrams as interactive HTML files to share with your team or clients.

What you should remember

Understanding the difference between MySQL and MongoDB really comes down to how they organize data.

In MySQL, you split information into separate tables and link them.
In MongoDB, you can keep everything together in one document or link collections loosely.

Each has its own advantages, the important thing is knowing which one fits your data and your project best.

DbSchema helps you explore both worlds without needing to write complex code. You can build your models visually, understand your data better, and even work offline if you want.

Try it now using something simple, like countries and cities - and you’ll see how powerful visual design can be.

DbSchema Database Designer
Visual Design & Schema Diagram

➤ Create and manage your database schema visually through a user-friendly graphical interface.

➤ Easily arrange tables, columns, and foreign keys to simplify complex database structures, ensuring clarity and accessibility.

GIT & Collaboration
Version Control & Collaboration

➤ Manage schema changes through version control with built-in Git integration, ensuring every update is tracked and backed up.

➤ Collaborate efficiently with your team to maintain data integrity and streamline your workflow for accurate, consistent results.

Data Explorer & Query Builder
Relational Data & Query Builder

➤ Seamlessly navigate and visually explore your database, inspecting tables and their relationships.

➤ Build complex SQL queries using an intuitive drag-and-drop interface, providing instant results for quick, actionable insights.

Interactive Documentation & Reporting
HTML5 Documentation & Reporting

➤ Generate HTML5 documentation that provides an interactive view of your database schema.

➤ Include comments for columns, use tags for better organization, and create visually reports.