Install MongoDB

Introduction

MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. It's described as a leading NoSQL Database. MongoDB has been used in the beloved MEAN stack. The benefits of using a document database like MongoDB means that you can work with JSON-style documents across your entire development stack.

About Documents Management

A record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.
{
   "_id" : ObjectId("54c955492b7c8eb21818bd09"),
   "address" : {
      "street" : "2 Avenue",
      "zipcode" : "10075",
      "building" : "1480",
      "coord" : [ -73.9557413, 40.7720266 ]
   },
   "borough" : "Manhattan",
   "cuisine" : "Italian",
   "grades" : [
      {
         "date" : ISODate("2014-10-01T00:00:00Z"),
         "grade" : "A",
         "score" : 11
      },
      {
         "date" : ISODate("2014-01-16T00:00:00Z"),
         "grade" : "B",
         "score" : 17
      }
   ],
   "name" : "Vella",
   "restaurant_id" : "41704620"
}


Collections

MongoDB stores documents in collections. Collections are analogous to tables in relational databases. Unlike a table, however, a collection does not require its documents to have the same schema.In MongoDB, documents stored in a collection must have a unique _id field that acts as a primary key

Download MongoDB

Requirements

MongoDB Community Edition requires Windows Server 2008 R2, Windows Vista, or later. The .msiinstaller includes all other software dependencies and will automatically upgrade any older version of MongoDB installed using an .msi file.

Download link : http://www.mongodb.org/downloads?_ga=1.67380945.1743686892.1461824612

1) Select your OS and OS architecture. You can check it using CMD, Type below command in CMD to find that information.
wmic os get caption //OS Version
wmic os get osarchitecture //OS Architechure
image

Install MongoDB

2) Right click the setup file and click ‘Install’. (Note : You want administrator privileges to install MongoDB)
3) Click ‘Next

image

4) Click ‘Next’ agree on term and conditions

image

5) You can select complete installation or Custom Installation. If you want to change installation location you should select custom installations.

image

6) Click ‘Install’ button to start an installation.

image

7) Strat installation.

image

8) Click ‘ Finish’ to finish Installation.

image


Configure MongoDB

MongoDB requires a data directory to store all data. MongoDB’s default data directory path is c:\data\db.  if you want to create another directory for datafiles
There are two methods to configure MongoDB
       1) Command line
       2) Config files change

Command line configuration

–dbpath <path> : the existent directory path, which is required to store data files. this is a most important option we need to specify, Note that, the directory path you are providing should exist otherwise process won’t start. If this path contains spaces then put all its path in double quotes. e.g. –dbpath “c:\Program Files”

–logpath <log-file-path>: the existent file path, used by mongo daemon process,for flush out logs instead of in standard console. If this path contains spaces then put all its path in double quotes
–port <port> :  port no. where MongoDB process listens for the connection from the client, it defaults to 27017 if not specified

1) Run the following command in command prompt (you may need to create the c:\mongo\data\db and c:\mongo\log folders before running the command)
mongod --logpath "c:\mongo\log\log.log" --logappend --dbpath 
"c:\mongo\data\db" --directoryperdb –install

2) If successful, you will see MongoDB in the Windows Services panel

image

Config file configuration

This is a template of config file
##store data here
dbpath=c:\mongo\data\db
##all output go here
logpath=c:\mongo\log\log.log
##log read and write operations
diaglog=3
You should create this file and save with ‘.config’ extention (example.config)
3) Link config file with MongoDB
mongod.exe --config c:\MongoDB\mongo.config

image

This starts the main MongoDB database process.
(I will recommend you first method to configure MongoDB)
4) Connect to MongoDB
c:\mongodb\bin\mongo

image

In next session, I will discuss with you how to connect MongoDB GUI tool and work with mongoDB
Install MongoDB Install MongoDB Reviewed by Lilantha Lakmal on 12:48:00 PM Rating: 5

1 comment:

  1. Thanks for sharing this informative article on Install MongoDB. If you want to mean stack development company for your project. Please visit us.

    ReplyDelete

Powered by Blogger.