Write at the beginning
Recently, I am learning about nodejs’s operation of mongodb. However, I found that every time I start mongodb, I need to type a long instruction. I have to go all the way from cd to mongodb’s bin directory and write a large list of things to start it. It is very annoying and easy to make mistakes. So I was wondering how to make it start quickly and conveniently.
Because the machine I am using is win7 system, so this article
mayOnly valid for win7 system.
Mongodb website download address:https://www.mongodb.org/downloads#produc …
Directly download the. msi file and install it to the specified directory. My installation path is
Then create a new one under the root directory
blogFolder, as a data storage directory (online tutorials are mostly named
data, you are free, you know).
At the same time, create a new one under the root directory.
logsA folder that serves as a repository for log files.
Now it may look like this:
Set system variables
The purpose of this step is to be executed directly on the cmd console.
mongodCommand instead of all the way to cd
\binDirectory to execute.
My computer-properties-advanced system settings-environment variables-system variables, find PATH, double-click edit, add at the end
; D:\MongoDB, pay attention to the front bonus number, finally click ok. As shown in the figure:
Now, we can open the command line directly by cmd and enter directly
mongod --dbpath=D:\MongoDB\blogIf there is this sentence at the end of the output, it means mongodb has been successfully started and the port number is 27017.
We enter in the browser
localhost:27017, the page will display “it looks like you are trying to access mongodb over http on the native driverport.” indicating a successful startup.
At this time, a new command line window will be opened to directly execute mongo’s instructions.
A faster way
Through the above steps, we have solved the problem of “cd all the way”, but we still need to write to start mongodb.
mongod --dbpath=D:\MongoDB\blog. As a very lazy person, I really don’t want to write such a long sentence every time. Is there a faster way? Yes!
We can start mongodb as a startup task and start it as the system starts!
Open cmd console and enter
mongod --dbpath=D:\mongodb\blog --logpath=D:\mongodb\logs\mongodb.log --install
At this time in
\logsOne will appear in the folder
mongodb.logFile, there are some mongodb logs.
Now mongodb can start with the system. In the future, we need to connect mongodb database, only need to input in cmd console.
net start mongodb, the console will output:
Mongodb needs to be closed, only input is required
net stop mongodb, the console will output:
We’re done! !