2. Unzip the installation file to drive C (note: there are no spaces in the installation path), configure "environment variables", and add %MONGODB_HOME%in to the "path";
3. Enter the DOS window and set the data storage directory (and port) and log output directory.
DOS command:
mongod-port-dbpath-log path-log append-directory perdb
Parameter description:
-port stands for database port, and the default value is 27017;
-dbpath indicates the data file storage path, which is generally set to% mongodb _ home% data.
-logpath indicates the log file storage path, which is generally set to% MongoDB _ home% logsmogodb.log
-logappend means log appending, which will be overwritten by default;
-directoryperdb represents a directory for each database;
4. After completing the above settings, MongoDB has been started, and a new DOS window is opened to execute "mongo.exe", and "MongoDB shell version:1.8.1"appears, indicating that the installation is successful.
5. At present, it is permission-free startup, and anything can be done. Then let's switch to admin first and create a root user. Execute the command:
"use management"->; " db.addUser("root "," root ")"-& gt; "db.auth("root", "root") ",as shown in the figure below:
6. Register MongoDB as a Windows service and let it start automatically; Execute the command:
mongod-bind _ IP 127 . 0 . 0 . 1-log path % MONGODB _ HOME % logsmongodb . log-log append-dbpath % MONGODB _ HOME % data-directory perdb-auth-install
note:
A. you must switch to the bin directory to execute this instruction.
B.- Authorized user rights must be added to take effect.
C. Except for "-auth" and "-install", other parameters should be consistent with the parameters for starting the service when you set up users, especially "-directoryperdb".
After the first configuration is completed, it will be effective to restart the mongo client without entering -u-p, but without any permissions. The correct access method is: mongo database name -u user name-p. Set additional users.
7. Interface after successful service installation:
8. If the installation fails:
Delete MongoDB service and execute the command:
Sc delete MongoDB
Start MongoDB service and execute the command:
net start“MongoDB”
9. There are two ways to open under 9.cmd. Net and sc, net are used to open services that are not disabled. The grammar is:
Start: net/sc startup service name
Stop: network/supply chain stop service name
10. In addition, sc can be used to open disabled services. The grammar is:
Sc Configuration Service Name Start = Demand//Manual
Sc condig service name start= auto // automatic
Sc configuration service name start= disabled // disabled.
Note: The above three commands must be followed by a space.
Mongo (also translated as mango) comes from humongous, which means huge. This is a high performance, open source and modeless document NOSQL database. Mongo is developed in C++ and provides the following functions:
Collection-oriented storage: suitable for storing objects and data in JSON form.
Dynamic query: Mongo supports rich query expressions. The query instruction uses JSON tags, which can conveniently query the objects and arrays embedded in the document.
Complete indexing support: including document embedded objects and arrays. Mongo's query optimizer analyzes query expressions and generates efficient query plans.
Query monitoring: Mongo includes a monitoring tool to analyze the performance of database operations.
Replication and automatic failover: Mongo database supports data replication between servers, master-slave mode and mutual replication between servers. The main goal of replication is to provide redundancy and automatic failover.
Efficient traditional storage method: support binary data and large objects (such as photos or pictures).
Automatic fragmentation supports cloud-level scalability: Automatic fragmentation supports horizontal database clustering, and additional machines can be added dynamically.
The MongoDB server can run on Linux, Windows or OS X platforms and support 32-bit and 64-bit applications. The maximum file size supported in 32-bit mode is 2GB.
Common startup parameters:
--dbpath specifies a specific storage directory to start, and creates it if it does not exist. The default directory is /data/db. Example:. /mongo–dbpath/var/data/mongo
–Port The specified port has been started. The default port is 270 17. Example:. /mongod–port 12345
How to use it under windows?
Direct start:
$ bin/mongod.exe # start the server.
$ bin/mongo.exe # starts the client connection.
Register as a service so that it can be started automatically when it is opened in the future.
$ bin/mongod.exe-logpath c:\ data \ log. log-logappend-dbpath "c:\ data \ db"-install # is mainly an installation parameter, so it is necessary to create a new c: \ data \ log.log file and a new c: \ data \ db directory.
Delete service
$ bin/mongod.exe-delete
When you register as a service, you can use Win+R to open it and go to services.msc to check the service status.
Common mistakes
1, monge.exe client reported an error when connecting: unable to connect to the server127.0.0.1shell/mongo.js: 79.
This is because monged.exe didn't start.
2. After many attempts, monged.exe failed to start and never found the reason.
This mistake has been bothering me for some time. Later, it was found that there was a mongod.lock lock file under c:\data\db. After deleting this file, just restart the server.
Service startup error: Error 2: The system cannot find the specified file.
Solution:
When installing the service, you need to use the full path of mongod.exe.
c:\ MongoDB-win32-i386- 1 . 8 . 2 \ bin \ mongod . exe-log path c:\ mongo
db \ logs \ mongo . log-dbpath c:\ MongoDB \ data \ d b-directory perdb-install
To delete a service
c:\ MongoDB-win32-i386- 1 . 8 . 2 \ bin \ mongod . exe-log path c:\ mongo
db \ logs \ mongo . log-dbpath c:\ MongoDB \ data \ d b-directory perdb-remove
And reopen the windows service window, the original service will disappear.