Getting started with MongoDB (installation and configuration)
I. Introduction
A non-relational database (NoSql), MongoDB is a powerful, flexible, and Scalable Data Storage Method. Because MongoDB is a document model, it is highly flexible and flexible, mongoDB allows you to smoothly develop Internet applications with large data volumes, high concurrency, and weak transactions, mongoDB's built-in horizontal Scaling Mechanism provides data processing capabilities from one million to one billion. It also supports MapReduce-based aggregation and geospatial indexing.
Ii. installation and configuration
1. Download and install
Http://www.mongodb.org/downloads
My system is 32 bits in Windows 7, so I downloaded the corresponding mongodb-win32-i386-2.6.8.zip
2. installation and configuration
Step 1: Decompress the package to a disk, for example, my unzipped Directory D: \ mongodb ,:
Step 2: configure the directory for storing logs and data. Otherwise, mongoDB cannot be started ,:
Run cmd.exe To Go To The DOS command interface, and then go to the cd D: \ mongodb \ bin directory. Next we will configure the files in the directory where logs and data are stored, we can use the help command to view which commands ,:
We found that (1) -- logpath arg: arg is the path for storing logs (2) -- dbpath arg: arg is the path for storing data files
First, configure the data directory. For example, if you want to store the data in the Directory D: \ mongodb \ data \ db, run cmd.exe to enter the DOS command interface, then run the cmdd.exe command in the directory cd D: \ mongodb \ bin ,:
Note: The error is reported because we need to manually create the path of the D: \ mongodb \ data \ db file first. We have created the path and executed it once. This time, it succeeded ,:
Configure the log Path. For example, if you want to store it in the Directory D: \ mongodb \ data \ log, run cmd.exe to enter the DOS command interface, enter the cdD: \ mongodb \ bindirectory, and run cmdd.execommand cmd.exe -- logpath = D: \ mongodb \ data \ log \ mongodb. log ,:
Step 3: test whether the configuration is normal.
Run cmd.exe to enter the doscommand interface, and then enter the cd D: \ mongodb \ bin directory. Run the mongo command to test the connection ,:
Error
Note: If the server is not started, we need to configure the MongoDB server by ourselves. We will create a mongodb under the D: \ mongodb directory. the config configuration file has two attributes: logpath and dbpath. The values are set respectively, that is, the path we Just configured ,:
Mongod.exe -- config d: \ mongodb. config to start the MongoDB server. The -- config option indicates that the server is configured through the information file d: \ mongodb. config at startup. :
Do not close this doscommand interface. The MongoDB server is running. I open a new doscommand interface, first go to the cd D: \ mongodb \ bin directory, run the mongo command to test the link ,:
The configuration is successful.
3. Add MongoDB to Windows Service
When we turn off the DOS command interface that runs the MongoDB server, we cannot connect to MongoDB. We need to add it to Windows Service like mySql, then start and close the service on the command line, so that we can conveniently operate and manage the service.
Next, we need to install MongoDB to Windows Service. The command used is -- install to set MongoDB to be installed as a server to Windows Service.
Step 1: Execute-install, start cmd as an administrator, enter the doscommand interface, first go to the cd D: \ mongodb \ bin directory, and execute
D: \ mongodb \ bin> mongod.exe -- dbpath = d: \ mongodb \ data \ db -- logpath = d: \ mongodb \ data \ log \ log.txt -- install -- serviceName "MongoDB ":
Step 2: Start/Close the MongoDB Service
Netstart mongodb starts the MongoDB Service
Net stop mongodb start MongoDB Server
Iv. Test the MongoDB shell.
Step 1: Run cmd.exe and go to the DOS command interface. First, go to the cd D: \ mongodb \ bin directory, run the mongo command, go to the shell, and view the database show dbs ,:
Step 2: Switch and generate a database
When switching the database, if the database does not exist, the database is directly generated. use test ::
Step 3: Create a set and save the data
Created a set named zhengcy.
Db. zhengcy. insert ({username: 'zcy '})
Step 3: search for all data in the zhengcy collection
Db. zhengcy. find ()