Install MongoDB on Windows and configure startup items

Introduction to MongoDB

Original text: http://www.tuicool.com/articles/v2YNz2

MongoDB (from the English word "Humongous", Chinese meaning "huge") can be applied to enterprises of all sizes, industries and applications An open source database of programs. Database based on distributed file storage. Written in C++ language. It aims to provide scalable high-performance data storage solutions for WEB applications. MongoDB is a high-performance, open source, schema-less document database, and it is one of the more popular NoSql databases.

MongoDB uses BSON as the format for data storage and transmission. BSON is a JSON-like binary serialized document that supports nested objects and arrays.

MongoDB is very similar to MySQL. Document corresponds to MySQL row, and collection corresponds to MySQL table.

1. The official website for downloading
MongoDB is: http://www.mongodb.org The
latest version of MongoDB is downloaded under the DownLoad menu of the official website: http://www.mongodb.org/downloads The
official website selects the windows version by default, download it directly msi file to the specified directory can be.
The latest version is 3.4.4, and the msi file is used for the installation of this blog.
2. Installation
My computer is a 64-bit win7 system, download the 64-bit msi installation package, install it to the specified directory E:

\mongodb, create a Data folder E:\mongodb\data under E:\mongodb, and then create db separately, log two folders, so far there are the following folders
E\mongodb\bin
E\mongodb\data\db
E\mongodb\data\log
Create a log file MongoDB.log in the log folder, namely E\mongodb\data\log\MongoDB.log

3. Two ways to start the program
3.1 Through cmd Start the command window to
open the command line window, switch to the E:\mongodb\bin directory and execute the following command:

where --dbpath is the specified database storage directory, here it should be noted that there are two "-"
to execute this command to create the mongodb database file to E:\mongodb\data\db directory
mongod --dbpath E:\mongodb\data\db
This is the command line window will print some startup information, the last line is displayed as the following information, it means the startup is successful
[initandlisten] waiting for connections on Port 27017
The database has been started at this time. This interface is the startup program of Mongo. After closing, you can directly double-click mongod.exe under the bin (note that it is d, this is the startup program).
This is to enter http://localhost in the browser: 27017/You can see that the display information is
It looks like you are trying to access MongoDB over HTTP on the native driver port.

Test the database operation
> help (see related information)

>db.foobar.insert({name:'zhangsan'}) (insert name, zhagnsan field value into foobar table, foobar table is a new table)

>db.foobar.find() (view foobar table data)

When we put mongod When .exe is closed, mongo.exe cannot connect to the database, so every time you want to use the mongodb database, you have to open the mongod.exe program, so it will be very troublesome. Next, we will install MongoDB as a windows service to start. 3.2 Run cmd.exe


in windows service mode > cd E:\mongodb\bin > E\mongodb\bin>mongod –dbpath "E\mongodb\data\db" –logpath "E\mongodb\data\log\MongoDB.log" --install --serviceName "MongoDB" where MongoDB.log is the log file that was started to be created, --serviceName "MongoDB" service name MongoDB Run the command successfully as shown below: The time service has been installed successfully, run >NET START MongoDB (start the service) 0003 >NET stop MongoDB (shutdown service) >


















> E\mongodb\bin>mongod --dbpath "E\mongodb\data\db" --logpath "E\mongodb\data\log\MongoDB.log" --remove --serviceName "MongoDB" (remove, note that it is not --install)
For other commands, please refer to the help command or the official website description.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326340359&siteId=291194637