DbSchema Database Designer

Install MongoDB & Create a Database | MongoDB Tutorial 2025



MongoDb Tutorial

In this lecture, you will learn how to install MongoDB Server, work with Mongo Shell to create your first database, and setting up collections within that database. This is a crucial step for working with MongoDB, as it will put the foundation for everything you’ll do with this NoSQL database.

I. Install MongoDB Server

Before you can begin creating databases and collections, you need to have MongoDB installed on your machine. Here’s how you can do it:

For Windows:

  1. Go to the Official MongoDB Website and download the latest version for Windows.

  2. Run the installer and follow the instructions on screen. Ensure you select the option to install MongoDB as a Service during installation.
    MongoDB for Windows

  3. After the installation, open Command Prompt and type mongosh to confirm MongoDB has been installed successfully. If it opens up the MongoDB shell, you’re ready to start.

For macOS:

  1. Open the Terminal and use Homebrew to install MongoDB with the following command:
    brew tap mongodb/brew
    brew install [email protected]
  2. Once the installation is complete, you can start MongoDB using the command:
    brew services start mongodb/brew/mongodb-community

For Linux:

  1. You can install MongoDB on Linux using Ubuntu.

    sudo apt-get install -y mongodb   
  2. Start the MongoDb service:

    sudo service mongodb start

II. Run Mongo Shell

No matter what type of operating system you’re using, the Mongo Shell is basically the place where you insert all your commands to interact with your MongoDB server.
For this tutorial, I will be using Windows. In the Command Prompt, type the mongosh command to open the Mongo Shell:

Method I. Create a MongoDB Database

In the shell you can run show dbs to see wich database you have on MongoDb Server.
Since you don’t have any database created yet you will get this ones:
admin....0.000GB
config...0.000GB
local....0.000GB

A database can be created with this simple command:

use flights

This allows you to reference the database you’re currently working in. In this case, we’re already in the flights database, as indicated by db.

Create a MongoDB Collection

To create a MongoDB collection, you can use the following method db.flightData.insertOne({}) to insert a document into the flightData collection:

  db.flightData.insertOne({
"departureAirport": "LHR",
"arrivalAirport": "TXL",
"aircraft": "Airbus A320",
"distance": 950,
"intercontinental": false
})

After pressing ENTER, you will receive a confirmation message indicating that the operation was successful. MongoDB will also automatically assign an Object ID to the newly inserted document.

Retrieve Data from the Collection

To retrieve data from the collection, use the following command:

db.flightData.find().pretty()

Note: .pretty() method is used to format the output in a more readable way, but it is not required for the query to work.

Once executed, the results will be displayed in a more structured format, similar to this:

Retrieve Data Find Pretty

Next Lesson: CRUD Operations

In the next article we will go deeper into CRUD operations:

  • Find documents using queries
  • Insert multiple records
  • Update existing data
  • Delete documents

Method II. Using DbSchema (a GUI Tool for MongoDB)

If you prefer a more visual and intuitive way to explore MongoDB, you can use a GUI tool like DbSchema. It helps you understand your database structure, manage collections, and run queries easily without needing to type commands manually.

👉 Download DbSchema for free here and simplify your MongoDB experience!

Read about how to connect to MongoDB and explore all the powerful features that DbSchema offers for working with MongoDB in this article.

Creating a New Database Visually in DbSchema

Once you’re connected to your MongoDB database with DbSchema, you can create a new database easily using just your mouse.

  1. Right-click on the left side of the Project Structure panel.
  2. Select “Create Database” from the menu.
  3. A pop-up window will appear: simply enter the name of your new database. Let’s call it “flights2”
  4. Click OK, and that’s it! Your new database is now created on your MongoDB server.

Create a Database with DbSchema

Create a MongoDB Collection

  1. Ensure that you have selected “flights2” on the left side to create a new collection in this database.

  2. To create a new collection, simply right-click on the main screen and choose Create Validator / Define Collection (we will discuss what a Validator is later in this course).

Create a Collection with DbSchema

  1. Name the collection “flightData”, just as we did in MongoShell. This will help us better understand how our database and collections appear in a GUI tool.

Create a Collection with DbSchema

  1. Click the “Add” button to add fields to this collection:
    • Enter the field name “_id”.
    • Select the Data Type (in this case, “ObjectId”) and check the Mandatory box.
    • Add the rest of the fields to your collection, then click OK.

Create a Field with DbSchema

  1. You will now see the structure of the newly created collection displayed in the diagram. At this stage, the collection is empty.

Insert Data into the Collection

Now, let’s add data to this collection using the Data Editor in DbSchema.

Create a Collection with DbSchema

  1. In the table header, click on the first icon, “Relational Data Editor”. A new tool will open, allowing you to start adding data.
  2. Click the “+” icon.
  3. Insert data into the JSON Document, which is already well-structured.
  4. Click “Execute & Keep Inserting”.

Insert Data into a Collection with DbSchema

Retrieve Data from the Collection

Now, let’s retrieve the data that we inserted into the collection.

  1. Click on the collection header and select “Query Editor”.
  2. DbSchema automatically generates the find query - just click “Run”.
  3. The results will be displayed in a table format, similar to Excel.

Retrieve Data from a Collection with DbSchema

And that’s it! This is how you can work with MongoDB in a simple and visual way, making everything easy to understand.

Click here to read the Next Lesson and learn how to dive deeper into CRUD operations:

  • Find documents using queries
  • Insert multiple records
  • Update existing data
  • Delete documents

Click here to read the first article about Introduction to MongoDB.

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.