【2023.04.28】Windows configuration MongoDB service

Environment: Windows11, Mongo 6.0.5 [this version does not have mongo.exe]

1. Background

One day, I wanted to use the MongoDB installed on my computer, but found that I couldn’t connect with Navicat. After checking, I found that the Mongo service was not enabled, but the installation was automatically enabled at that time. I don’t know what happened to the computer during this period. Open the Mongo service in the service panel and find that there is no such service, so we have to manually configure the service

As shown in the figure: there is no Mongo service in the name columninsert image description here

2. Operation

2.1 Configure environment variables

Settings –> System –> System Information –> Advanced System Settings –> Environment Variables –> Path, just add the bin folder under the Mongo installation directory.
insert image description here
insert image description here
insert image description here
insert image description here
After the configuration is complete, enter in the terminal mongod -versionto display the version of Mongo, which proves that the configuration is successful:
insert image description here

2.2 Configure local Windows MongoDB service

Create a new configuration file mongo.config in the bin directory of the Mongo installation folder

Create a new configuration file mongo.config:

  • First create a mongo.txt file, then open it, click "Save As", change the file type below to "All Types", and change the file name to mongo.config.

  • Open mongo.config with Notepad and enter:

dbpath=D:\software\MongoDB\data【安装目录下的data文件夹】
logpath=D:\software\MongoDB\log\mongod.log【安装目录下的log文件夹】

Open cmd as an administrator, first jump to the bin directory of the Mongo installation directory (you can ignore it if you have configured the environment variables)

Then type:

mongod --config "mongo.config的路径" --install --serviceName "MongoDB"

That is, install the service according to the mongo.config configuration file just created, named MongoDB.
insert image description here

Once you're done, check your local services again.

insert image description here
The Mongo service has appeared, and after setting the automatic startup, Navicat can also connect

insert image description here
You're done!

Guess you like

Origin blog.csdn.net/a6661314/article/details/130422511