Installation and Basic Configuration

Introduction

MongoDB is a popular NoSQL database known for its high performance, scalability, and flexibility. This guide will walk you through the process of installing and configuring MongoDB on your system. Whether you are using Windows, macOS, or Linux, this step-by-step tutorial will help you get started with MongoDB.

Prerequisites

Before we begin, ensure you have the following:

  • Administrator access to your system

  • Basic knowledge of command-line interface

Installation

Windows

Step 1: Download MongoDB

  1. Go to the MongoDB Download Center and select the MongoDB Community Server.

  2. Choose the version compatible with your Windows OS and download the installer.

Step 2: Install MongoDB

  1. Run the downloaded .msi file.

  2. Follow the setup wizard, selecting the Complete setup type.

  3. Choose to install MongoDB as a service.

  4. Configure the Data and Log directories (default paths are usually sufficient).

Step 3: Verify Installation

  1. Open Command Prompt.

  2. Run the command:

    This should display the installed MongoDB version.

macOS

Step 1: Install Homebrew

If you haven't installed Homebrew, run:

Step 2: Install MongoDB

  1. Tap the MongoDB formula:

  2. Install MongoDB:

Step 3: Start MongoDB

  1. Start MongoDB as a service:

  2. Verify installation by checking the version:

Linux (Ubuntu)

Step 1: Import the Public Key

Step 2: Create a List File for MongoDB

Step 3: Reload the Local Package Database

Step 4: Install MongoDB Packages

Step 5: Start MongoDB

Step 6: Verify Installation

Basic Configuration

Configuration File

MongoDB’s configuration file is located at /etc/mongod.conf by default. Key sections include:

  • Storage: Configures the storage engine and database file paths.

  • Net: Configures network settings including the port MongoDB listens on.

  • Security: Configures security options like authorization.

Example Configuration (/etc/mongod.conf)

Starting and Stopping MongoDB

Windows

Use the net command:

macOS

Using Homebrew services:

Linux

Using systemctl:

Enabling Authentication

  1. Create an administrative user.

  2. Restart MongoDB with authentication enabled.

  3. Authenticate using the created user:

Conclusion

You have now installed and configured MongoDB on your system. This guide covered the essential steps to get you started with MongoDB, including installation, basic configuration, and enabling authentication. For more detailed configuration and advanced features, refer to the MongoDB documentation.