MongoDB Installation

What is MongoDB?

MongoDB is a versatile, document-oriented NoSQL database that offers a flexible, scalable, and high-performance solution for a wide range of applications. Its ability to handle unstructured data, support for rich queries, and horizontal scalability make it a popular choice for modern application development.

Key MongoDB Features:

  • Document based: MongoDB stores data in documents (field-value pair data structures, NoSQL);
  • Scalable: Very easy to distribute data across multiple machines as your users and amount of data grows;
  • Flexible: No document data schema required, so each document can have different number and type of fields;
  • Performant: Embedded data models, indexing, sharding, flexible documents, native duplication, etc.
  • Free and open-source, published under the SSPL License.

Creating a Hosted Database with Atlas

Navigate to the https://cloud.mongodb.com/ address and login with your google account.

After logging in, locate the ‘Projects’ tab on the left side and click on the ‘New Project’ button.

Enter ‘test-app’ as the project name and then click the ‘Next’ button.

After the project is created, we need to establish a Cluster for the connection. Click the ‘Create’ button.

Select the Free option and click the ‘Create Deployment’ button.

Note your username and password, then click the ‘Create User’ button.

Connecting to the Database with Compass GUI

Choose ‘Developer Tools’ > ‘Compass GUI’ and proceed to download the MongoDB Compass application onto your computer. Additionally, ensure you copy the connection string for use in the Compass application.

Open the Compass application, paste the connection string and click the ‘Connect’ button.

We are now connected to MongoDB and can proceed to create a new database.

After creating the database, you can confirm its existence through the cloud. Go to the Collections tab within the Cluster to see if the ‘natours’ database has been successfully created.

Connecting to the Database with MongoDB Shell

To use MongoDB shell, it must first be installed on your computer. MAC users should execute the given command in their terminal. Windows users, on the other hand, may download it directly using the provided link.

brew install mongosh

Copy the connection string from the ‘Developer Tools’ > ‘MongoDB Shell’ section.

Open the terminal and insert the connection string. After entering the password, you will establish a connection to the database through the terminal.

To view all databases, we can use the command “show dbs”.