MongoDB Getting Started
What is MongoDB?
- MongoDB is a document database. It stores data in a type of JSON format called BSON. A record in MongoDB is a document, a data structure composed of key-value pairs similar to JSON objects.
Document?
- Records in a MongoDB database are called documents, and the field values may include numbers, strings, booleans, arrays, or even nested documents.
Installation
To install MongoDB, follow the steps below:-
For Windows:-
Download the latest release here. Make sure that you are downloading the appropriate file.
In the Version dropdown, select the version of MongoDB to download.
In the Platform dropdown, select Windows.
In the Package dropdown, select msi.
Click Download.
Run the Windows Installer from the Windows Command Interpreter.
Open CMD as Administrator.
Use the .msi installer to install all MongoDB binaries, including MongoDB Compass.
From the Command Interpreter, go to the directory containing the .msi installation binary and run:
msiexec.exe /l*v mdbinstall.log /qb /i mongodb-windows-x86_64-6.0-signed.msi
- The operation installs the binaries to the default directory.
C:\Program Files\MongoDB\Server\6.0\bin.
The bin directory contains several binary files along with mongod and mongo. To run it from another folder, you could add the path in the system path. To do it:
Right-click on My Computer and select Properties.
Click on the Advanced system settings on the left pane.
Click on Environment Variables... under the Advanced tab.
Select Path from the System variables section and click on Edit...
Before Windows 10, append a semi-colon and paste the path given above. From Windows 10,
there is a New button to add a new path.
Click OKs to save changes.
Now, create a folder named data having a sub-folder named DB where you want to run the server.
Start the command prompt from there. Either changing the path in cmd or clicking on the Open command window here which would be visible after right-clicking on the empty space of the folder GUI by pressing the Shift and Ctrl keys together.
Write the command to start the server:
mongod
- It would start the server on port
27017
by default.
- It would start the server on port
Open another command prompt and type the following to start the client:
mongo
By default, it connects to the test database. If you see the line connecting to the test. Then you have successfully installed MongoDB. Congrats! Now, you can test Hello World to be more confident