Install MongoDB
Go to http://www.mongodb.org/to find the Windows 32-bit installation program, which is actually a green program. This document uses mongodb-win32-i386-1.6.0.zip as an example.
Configure to run MongoDB
Decompress the downloaded mongodb compressed package to the target Directory, such as D:/mongodb. Open the cmd command line and enter:
The code is as follows: |
|
D:/mongodb/bin> mongod.exe-dbpath d:/mongodb/db |
There is no db folder in the d:/mongodb Directory. You need to create one by yourself. At this time, the mongod process runs and then open a cmd window and enter:
The code is as follows: |
|
D:/mongodb/bin/cmd.exe |
Go to mongodb command mode
The code is as follows: |
|
MongoDB Shell Version: 1.6.0 Connection to (databaseName) > Show dbs Admin Local |
You can check the database status in advance. By default, there are two databases: admin and local.
>
The code is as follows: |
|
Use testdb; open the database. If not, create one immediately. > Db. Py. save ({a: 10}); save a message to the collection PC. If there is no collection, create one immediately. > Db. Py. find (); retrieve all records {"_ Id": ObjectId ("4c469967dd6f000000001637 & Prime;)," a ": 10} > Show collections; show all collection names - System. indexes; |
System usage
Help is a help command. You can run it at any time to view the command prompt.
Configure the MongDB service
To avoid starting MongoDB every time you open the cmd window, you can register it as a service. The cmd command is:
The code is as follows: |
|
D:/mongodb/bin/mongod.exe-dbpath d:/mongodb/db-logpath d:/mongodb/log-install |
Although this command can be registered with the windows service, but I encountered a problem that could not be started, the prompt: "Error 1053, the service did not respond to the startup or control request in time ". When I was depressed, I thought of calling bat batch processing with a VBS file to hide the cmd command running in the background.
First, create the bat file:
The code is as follows: |
|
Mongo-start.bat content d:/mongodb/bin/mongod.exe-dbpath = d:/mongodb/db-logpath = d:/mongodb/log Mongo-stop.bat content taskkill/f/t/im cmdd.exe |
Create a vbs file:
The code is as follows: |
|
Mongo-start.vbs: Set ws = CreateObject ("Wscript. Shell ") Ws. run "cmd/c d:/mongodb/mongo-start.bat", vbhide Mongo-stop.vbs: Set ws = CreateObject ("Wscript. Shell ") Ws. run "cmd/c d:/mongodb/mongo-stop.bat", vbhide |
In this way, you can call the vbs file to start and stop MongoDB and run it in the background.
MongoDB installation error 1053 solved
Download Windows installation package mongodb-win32-i386-2.4.0.zip: http://www.mongodb.org/downloads
Decompress the package to disk D:/mongoDB, and create two folders in mongoDB: data and logs, because you need to specify the data storage
Logs directory, which is not automatically created.
Then run the CMD command line to install mongoDB to the system service:
The code is as follows: |
|
> D:/mongoDB/bin/mongod.exe -- bind_ip 127.0.0.1 -- logpath D:/mongodb/logs/mongodb. log -- logappend -- dbpath "D:/mongodb/data" -- directoryperdb -- serviceName MongoDB -- install |
Start:> net start MongoDB