English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Now let's see how to install MongoDB on Windows.
To install MongoDB on Windows, please first download fromhttps://www.mongodb.com/download-centerDownload the latest version of MongoDB .
Enter the required details and select Server Tab, where you can select the MongoDB version, operating system, and package as:
Now install the downloaded file. By default, it will be installed in the folder C:\Program Files\.
MongoDB requires a data folder to store its files. The default location of the MongoDB data directory is c:\data\db. Therefore, you need to create this folder using the command prompt. Execute the following command sequence.
C:\>md data C:\md data\db
Then you need to specify where to dbpath set mongod.exe directory created. Similarly, use the following command.
In the command prompt, navigate to the bin directory of the current MongoDB installation folder. Assuming my installation folder C:\Program Files\MongoDB
C:\Users\XYZ>d:cd C:\Program Files\MongoDB\Server\4.2\bin C:\Program Files\MongoDB\Server\4.2\bin>mongod.exe --dbpath "C:\data"
This will display waiting for connections in the console output ( “) message
To run MongoDB, you need to open another command prompt and enter the following command.
C:\Program Files\MongoDB\Server\4.2\bin>mongo.exe MongoDB shell version v4.2.1 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("4260beda-f662-4cbe-9bc7-5c1f2242663c") } MongoDB server version: 4.2.1 >
This indicates that MongoDB has been installed and is running successfully. Next time you run MongoDB, just enter the command.
C:\Program Files\MongoDB\Server\4.2\bin>mongod.exe --dbpath "C:\data" C:\Program Files\MongoDB\Server\4.2\bin>mongo.exe
Run the following command to import the MongoDB public GPG key-
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Use the following command to create /etc/apt/sources.list.d/mongodb.list file.
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
Now issue the following command to update the repository-
sudo apt-get update
Next, use the following command to install MongoDB-
apt-get install mongodb-10gen = 4.2
In the above installation, the current MongoDB version is2.2.3Make sure to always install the latest version. Now, MongoDB has been successfully installed.
sudo service mongodb start
sudo service mongodb stop
sudo service mongodb restart
To use MongoDB, please run the following command.
mongo
This will connect you to a running MongoDB instance.
To get the list of commands, please input in the MongoDB client. db.help()This will provide you with a list of commands, as shown in the following screenshot.
To get statistics about the MongoDB server, please type the command in the MongoDB client. db.stats() This will display the database name, the number of collections in the database, and the number of documents. The output of the command is displayed in the following screenshot.