Total Pageviews

Sunday, January 22, 2017

How to Install MongoDB like a Pro



1. Go to the URL : https://www.mongodb.com/download-center/community/releases/archive

2. Select  Software for your computer e.g: for Windows , shown below




 3. Select a binary in .zip format , from the link:

4. Download it into a repository, and extract it into an installation directory.

5. Create data directories for installation:

  1. D:/Mongo/Data – for data files
  2. D:/Mongo/Log – for log files
  3. D:/Mongo/Config – for configuration files
6. Create a configuration file- [mongod.conf] and paste the content below:

storage:
   dbPath: "C:/Mongo/Data"

systemLog:
   destination: file
   path: "C:/Mongo/Log/mongod.log"


Note: it must be in YAML format that is 3 space from left end.

7. We need to give user(a service account) full access to this installation directory, form the same we will use this command:

Icacls d:\mongo /grant Avinash:(OI)(CI)F

8. Now, install mongo db as service on windows server , using command:

mongod --install --config d:\mongo\config\mongod.conf --serviceUser Avinash --servicePassword ******* 

9. Now, we will verify whether it is installed or not.

sc qc mongodb

10. We will start the mongodb service now, by running the command:

net start mongodb

11
. Create a db:

 use my_test_db

12. Create a user:

db.createUser(
  {
    user: "avinashthakur",
    pwd: "Bangalore#12345",
    roles: [
       { role: "readWrite", db: "my_test_db" },
       { role: "readWrite", db: "test" },
       { role: "readWrite", db: "admin" }       
    ]
  }
)

13.It is ready to use. You may follow my other article for CRUD operation in Mongodb


No comments:

Post a Comment