Installing MongoDB on Windows 10
The following steps cover the installation and basic configuration of MongoDB so that even a beginner without background knowledge can install the database on Windows 10 for use with OPC Router's MongoDB plug-in
Downloading MongoDB
- Please open your internet browser and go to the MongoDB website www.mongodb.com.
- Click on the green “Try Free” button at the top right.
- On the following page, select “On-premises” and then “MongoDB Community Server“.
- The current database version is now displayed on the right-hand side of the screen and you can click on the green download button with the preset values.
Unpacking and basic installation for MongoDB
- Open the downloaded file with a double click. After a short system check, you can start the installation by clicking on “Next“.
- In the following window, please tick the box to accept the license agreement and then click on “Next” again.
- The easiest way is to install all program features: Click on the preselected field “Complete“.
- Accept the information of the “Service Configuration” and click on “Next” again.
- You can also leave the additional installation of MongoDB Compass (a useful graphical user interface) selected and click on “Next” again.
- With a final click on “Install“, the installation is now carried out. If further windows of your Windows appear asking you to “Allow changes“, please confirm with “Yes“.
- After a short period of time, you can complete the installation by clicking on “Finish“. MongoDB Compass may start automatically. Click through any information windows that may appear and exit MongoDB Compass, which is not covered in this how-to.
Making Your MongoDB Installation Easier to Use
- In order to be able to use MongoDB in the most user-friendly manner, a few small adjustments are now necessary in Windows.
- Open Windows Explorer and browse to C:\Program Files\MongoDB\Server\[Version]\bin.
- Right-click here on “bin” and select “Copy address” to copy the file path to the clipboard.
- Now type “var” in Windows search and click on the suggestion “Edit system environment variables” from the Control Panel
- In the system properties that now appear under the tab “Advanced“, click on the button “Environment variables” at the bottom.
- In the lower section “System Variables“, double-click on Path and the “Edit Environment Variable” window appears.
- Click on “New” and paste the path of the MongoDB installation from the clipboard using CTRL-V then confirm the open windows by clicking OK.
- Now our MongoDB calls and commands are comfortably accessible from all directories.
- The last thing we have to do is create the default database directory for MongoDB - first launch a Windows CMD prompt.
- In the command prompt we now create the default MongoDB directory with “
md c:\data\db“. If no error message appears, we have completed the installation and can subsequently start and test the installed MongoDB in the command prompt.
Starting and Testing MongoDB
- Still in the CMD prompt, you can start the database with the command “
mongo“. - With the command “
show dbs“, the three preset databases admin, config and local should now be displayed. - To check the functionality, you can now create your own database with the name “NewDB” using the command “
use NewDB“. - Here you can now insert a first data record: The command “
db.items.insert ({name: “name”})” creates a first data entry. With the command “db.items.find()” you can check whether the data set with ObjectID is now available. With the command “show dbs“, which is executed again, MongoDB should now show you not only the three standard databases but also the “NewDB” you have just created.
The free trial of OPC Router is available here, which supports both reading and writing for MongoDB.