Starting MongoDB Database

Start MongoDB
Previous post Installation  link
In this Page:
  • Adding Entries in Environment Variables
  • Starting MongoDB
  • Creating First Database

Start MongoDB
To start the mongodb service we have to add the path in environment variables otherwise we  have to mention full directory path to startup.
  • Using Web Browser
  • Using Command Prompt

  1. Using Web Browser

To start from web browser we can use localhost or provide IP address.
- HTTP interface for MongoDB Deprecated since version 3.2 :)


Default port of MongoDB is 27017

  1. Start Mongo from Command:

Error:

'mongo' is not recognized as an internal or external command, operable program or batch file.

Resolution:

Make entry in environment variables as Path:

 
Check of entry is added :


Run from command prompt to start mongodb service:
C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe or simply mongod.exe

I got error when starting, as shown below:



Problem: I’m currently using 32 bit of windows OS
Because you are using the MongoDB on a 32bit machine, the storage engine WiredTiger is not supported on 32bit machine. 


Resolution: Change your storage engine to the engines that are suitable for 32bit system,like mmapv1, and run mongod again.

Type in cmd:

mongod.exe --storageEngine=mmapv1













Another error when starting up: MongoDB requires a data directory to store all data. MongoDB’s default data directory path is \data\db if it is not found following error shows:



Resolution:
Create this folder by using cmd or by graphically.
Cmd:
md \data\db

You can specify an alternate path for data files using the --dbpath option to mongod.exe, 
For example:
C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe --dbpath d:\anurag\mongodb\data

If your path includes spaces, enclose the entire path in double quotes,
for example:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"

Create folders:


As directory is created in C drive:



Now run mongod.exe from command it will Run Successfully:

At this time it will show firewall warnings, click allow once:





















When you see the waiting for connections messages, it means that MongoDB has started successfully.

After starting services, Some new files are created inside data folder.


Files in diagnostic.data folder:



Creating Database:-

Start the service 
Then type 
>show dbs - It will show available databases.
>use test- Create a database named test
>cls- To clear screen
But we have no data inside so it will not showing when used show DBS command.



Inserting data into database, after inserting it will show in show dbs result:
MongoDB database stores its data in collections as compared to RDBMS that store in tables.


Until you add some collection in database it will not create that database:





After adding collections physically files are created on specified drive.