The method of quickly starting mongodb under win7

  mongodb, node.js

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 articlemayOnly valid for win7 system.

Download installation

Mongodb website download address: …
Directly download the. msi file and install it to the specified directory. My installation path isD:\mongodb
Then create a new one under the root directoryblogFolder, as a data storage directory (online tutorials are mostly nameddata, 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:


Start mongodb

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 browserlocalhost: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 foldermongodb.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 start mongodb, the console will output:
Mongodb needs to be closed, only input is requirednet stop mongodb, the console will output:
We’re done! !