Prepare the MongoDB Environment
1. Install MongoDB
MongoDB installation is very simple. You only need to extract the downloaded MongoDB compressed file to any directory and add the bin directory to the path environment variable of the system.
2. Start MongoDB
Before starting MongoDB, you must manually create a directory for storing MongoDB data files, such as D: \ mongo_data.
Run mongod -- dbpath = D: \ mongo_data on the command line.
Tip: manually create a file with the suffix "bat". The file name is arbitrary and the content is mongod -- dbpath = D: \ mongo_data. Double-click the file to start the MongoDB service, you do not need to execute the startup command on the command line every time.
In the shell that starts the server, you can type Ctrl-C to completely stop running mongod.
You can also use the command to install mongodb as a service:
D: \ mongodb \ bin \ mongod.exe -- logpath D: \ mongo_log \ mongodb. log -- logappend -- dbpath D: \ mongo_data -- directoryperdb -- serviceName MongoDB -- install
Remove this service from the System Service: D: \ mongodb \ bin \ mongod.exe -- logpath D: \ mongo_log \ mongodb. log -- logappend -- dbpath D: \ mongo_data -- directoryperdb -- serviceName MongoDB -- remove
3. Connect to the MongoDB Server
In the command line, you can use the mongo command to connect to the MongoDB server. Enter the following mongo command to connect to the local database named test by default. If you want to connect to a remote database, you can use the mongo ip: port