Contact Us

Kockpit is here to help you

Business Form

Arpit Dubey

Installation of Mongo DB Community Edition

Introduction to Mongo DB

Before we proceed to the installation of Mongo DB, we should first get an idea of what Mongo DB is and its usage.

Mongo DB is an open-source document-oriented database with syntax written in C++ program instead of SQL, commonly referred to as a NoSQL database management program. It is used as an alternative to standard relational databases. NoSQL database is very useful for working with large distributed datasets. Mongo DB is a tool that can manage text-focused, storing, or extracting data.

Mongo DB supports different types of data. It is one of the unrelated web technologies that first appeared in the mid-2000s under the NoSQL declaration. It is used in large data systems and other processing functions that incorporate data that do not fit the rigid relational model. Instead of using tables and rows as on a related website, Mongo DB architecture is made up of collections and documents.

Advantages of Mongo DB

The Mongo DB has numerous advantages over RDBMS:

  • Mongo DB doesn't have relationships similar to like RDBMS. The documents in Mongo DB are logically related to each other, which can be further modeled either by Embedded methods or Referenced methods. This approach assists in maintaining all the related data to be contained in a single document so that the data can be easily retrieved and updated.
  • MongoDB has the capability to hold different documents where the features of the document, like the number of fields, content, and size, can differ from one document to another.
  • Structure of a single object is clear.
  • No complex joins.
  • MongoDB supports dynamic queries on documents by using a document-based query language that's almost as powerful as SQL.
  • It is easy to scale.
  • There is no need for conversion/mapping of application objects to database objects.
  • Uses internal memory for storing the working set, enabling faster access to data.

Applications of Mongo DB

Mongo DB is widely applicable in various sectors and areas:

  • Document-Oriented Storage - Data is stored in the form of JSON-style documents.
  • Index on any attribute
  • Replication and high availability
  • Auto-Sharding
  • Rich queries
  • Fast in-place updates
  • Professional support by MongoDB
  • Organizations can use Mongo DB with its ad-hoc queries, targeting, upload rating, integration, JavaScript third-party server usage, and other features.

Difference between Mongo DB and RDBMS

Tool for Data Analytics:

MongoDB is a document database that offers high performance, high vacuity, and easy scalability. However, due to its reliable features like a key-value store, MapReduce computation capability, and document-acquainted NoSQL, MongoDB is considered the database for Data Analytics and Big Data processing.

The main idea behind MongoDB is to save as important functionality as possible while allowing vertical scale and, at the same time, to make an inventor's life a little further elegant and manageable. Moreover, it offers essential querying features for fast reclamation, analysis, and consultancy solutions for big data and Business intelligence. Finally, its flexible schema makes it a natural choice for unshaped datasets.

Installation Process:

First, you need to install the downloaded file. Then, it will be installed in the folder C:\Program Files\ by default.

A data folder is required to store files in MongoDB. The default location for the MongoDB data directory is c:\data\db. Hence, you need to create this folder by using the Command Prompt. Then, execute the following command sequence.

C:\>md data

C:\md data\db

Then you need to specify 'set dbpath' to the created directory in mongod.exe. To specify, input the following commands in the command prompt and navigate to the current bin directory in the MongoDB installation folder. Let's consider the installation folder to be: C:\Program Files\MongoDB

C:\Users\XYZ>d:cd C:\Program Files\MongoDB\Server\4.2\bin

C:\Program Files\MongoDB\Server\4.2\bin>mongod.exe --dbpath "C:\data"

This command in the command prompt will show a "waiting for connections" message on the console output. This message indicates that the mongod.exe process is running successfully.

Now, to run MongoDB, you need to open another command prompt and issue the following command.

C:\Program Files\MongoDB\Server\4.2\bin>mongo.exe

MongoDB shell version v4.2.1

connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("4260beda-f662-4cbe-9bc7-5c1f2242663c") }

MongoDB server version: 4.2.1>

This will show that MongoDB is installed and running successfully. Next time when you run MongoDB, you need to issue only commands.

C:\Program Files\MongoDB\Server\4.2\bin>mongod.exe --dbpath "C:\data"

C:\Program Files\MongoDB\Server\4.2\bin>mongo.exe

1. Download Installer:

You can download the Mongo DB Community .msi installer from the link provided below: https://www.mongodb.com/try/download/community?tck=docs_server

In the version, click on the dropdown button, and select the Mongo DB version to download.

  • From the Platform download, select Windows.
  • In the dropdown menu, select Package.
  • Click Download
2. Run the Mongo DB Installer

Open and run the installer from Windows Explorer or File Explorer:

  • Navigate to the location where you have downloaded the Mongo DB installer (.msi file). By default, this is your Downloads directory.
  • Double-click the .msi file.
3. Follow the Mongo DB Community Edition installation guide.

The wizard moves you through Mongo DB and Mongo DB Compass.

  • Select Setup Type

You can choose either Done (Recommended by most users), or Custom set type. The complete setup option includes Mongo DB and Mongo DB tools in the default location. The custom setup option allows you to specify which functionality is installed and where.

  • Service Configuration
  1. Starting with Mongo DB 4.0, you can set Mongo DB as a Windows service during installation or simply install binaries.
  2. If you choose not to configure Mongo DB as a Windows Service, uncheck the Install Mongo D as a service.
  • Install Mongo DB Compass:
  1. This is optional if you want to install Mongo DB or not. If so, select the Mongo DB compass option to install.
  2. When Ready, click install.
  3. After Installation, Restart the PC and check the version of Mongo DB in Console.
  • Add Mongo DB Path in the user variables.
  • Type Mongo -version
  1. After getting the Mongo DB Version Message, it means you have successfully installed Mongo DB.
  2. Connectivity of Python and Mongo DB:
  3. Open your code Editor and install Mongo Client through pip.
    1. Pip install MongoClient

Code for Connectivity with Mongo DB is as Follows:

#Importing Libraries

from pymongo import MongoClient

import datetime as datetime

#Creating MongoClient

client=MongoClient()

#Assigning Port for Mongo DB which is by Default 27017

client = MongoClient('mongodb://127.0.0.1:27017/'')

#Creating Database

mydatabase = client['Students']

#Creating Collections

collection=mydatabase['studentscores']

collection2 =mydatabase['studentscores2']

# Creating Documents in collections

data = [ {“user”:“Krish“, “subject”:“Database”, “score”:80},
{“user”:“Amit“, “subject”:“JavaScript”, “score”:90},
{“user”:“Amit“, “title”:“Database”, “score”:85},
{“user”:“Krish“, “title”:“JavaScript”, “score”:75},
{“user”:“Amit“, “title”:“Data Science”, “score”:60},
{“user”:“Krish“, “title”:“Data Science”, “score”:95}
]


data2 = [ {“user”:“Rohan“, “subject”:“Database”, “score”:80},
{“user”:“Mohan“, “subject”:“JavaScript”, “score”:90},
{“user”:“Shyam“, “title”:“Database”, “score”:85},
{“user”:“Vyom“, “title”:“JavaScript”, “score”:75},
{“user”:“Ram”, “title”:“Data Science”, “score”:60},
{“user”:“Gyan“, “title”:“Data Science”, “score”:95}]

Conclusion:

This article covers only general aspects and basic knowledge of the Mongo DB database. More articles on Mongo DB will be uploaded in the future. Do share your feedback or write comments if you find anything incorrect or misleading.

Check out Kockpit Analytics for various Mongo DB-based business analytical and big data solutions and products.