Quick Links:
To configure MongoDb you have to follow below steps.
I have install mongodb in my local folder "C:\mongodb" , to see install steps (click here)
Step 1) Once MongoDb is installed, you should go to folder "C:\mongodb" to verify the if bin folder along few files is created.
Step 2) Open command prompt and navigate to "C:\mongodb\bin"
Step 3) Lets configure location for data and log file
Create below folders in "C:\mongodb" folder to store database
- "c:\mongodb\data"
- "c:\mongodb\data\db"
- "c:\mongodb\log"
Now create file "C:\mongodb\mongo.config" and save below text in the file
- dbpath=C:\mongodb\data\db\
- logpath=C:\mongodb\log\mongo.log
Step 4 ) Set environment variable, Search "Advanced system settings" and open environment variable
In environment variable à system variables à Pathà Click edit
Click new and add path for bin folder
Step 5) Now open command prompt (Run as administrator ) and run below command to setup configuration
- mongod.exe --config="C:\mongodb\mongo.config"
- mongod --directoryperdb --dbpath c:\mongodb\data\db --logpath c:\mongodb\log\mongo.log --logappend
If after executing second command you notice your command is running even after few seconds, that means your mongodb engine have started and now you should directly jump to step (6)
- Mongod: This is nothing but mongodb exe file
- --directoryperdb : To share directory perdb
- --dbpath c:\mongodb\data\db : To configure default db path for all database
- --logpath c:\mongodb\log\mongo.log : To configure default log path
- –logappend: This will append the system configuration now
- --config="C:\mongodb\mongo.config": Setup configuration
Step 6) Now to start your mongodb instance, from command prompt run : mongod --dbpath "C:\mongodb\data\db"
Once you get below message you are good to connect to MongoDB instance
You will also see the entries here once you connect to mongodb
Step 6) Connecting mongodb
You can connect to mongodb shell or from GUI window (I always prefer shell i.e. 6a)
6a. To connect mongodb shell, Open command prompt and type "mongo", If this doesn't work go to mongodb installation directory "c:\mongodb\bin" and run command mongo.
This will open mongo db shell
Now your mongo db promp is ready for execution of first command, jump on step 7 and enjoy😊
6b) You can also open Mongo db compass from your start menu, it will look like this
I am connecting to local host at default port 27017 and gave it name "demo"
I am connected to my mongodb instance now.
Step 7) Now Lets Run My First command on Mongo DB
On shell I am ruuning this command to see databases available in my server
>Show dbs
And here is the output "List of databases"
So now you are ready to start your practice on mongodb machine, Good luck
Quick Links:
Quick Links:
No comments:
Write comments