1. MongoDB Installation
Three versions of the website are available for download:
- MongoDB for Windows 64-bit
suitable for 64-bit Windows Server R2, Windows 7, and the latest version of the Window system.
- MongoDB for Windows 32-bit
suitable for the 32-bit Window system and the latest Windows Vista. MongoDB databases on 32-bit systems have a maximum of 2GB.
- MongoDB for Windows 64-bit Legacy
suitable for 64-bit Windows Vista, Windows Server 2003, and Windows Server 2008.
MongoDB official website: MongoDB Downloads pages
Installing MongoDB
Select the Custom installation mode and select the installation directory d:\MongoDB
Note: MongoDB is independent and has no dependencies on any other systems. You can run MongoDB in any folder of your choice. So you can install MongoDB (for example) in any folder D:\test\ MongoDB
. Be careful to avoid Chinese catalogs.
2. MongoDB Run
Open the Administrator command prompt
You need to execute the installation command through the command prompt in administrator mode.
Administrator command prompt open mode:
Shortcut key win+r
to open the Run window, enter cmd
Shortcut key Ctrl + Shift + Enter
, you can open the Administrator command prompt. (Win Xp/win 7)
Setting up the MONGODB runtime environment
MongoDB needs the data directory to store all the data, its default data directory is \data\db
, you can mongod.exe --dbpath
specify the MongoDB data directory through the command. For example:
mkdir D:\mongodb\data\db;d:\mongodb\bin\mongod.exe--dbpath D:\MongoDB\data\db
If the path contains spaces, enclose the entire path in double quotation marks, for example:
D:\MongoDB\bin\mongod.exe--dbpath "D:\MongoDB DB data"
Seeing the words at the bottom of the tip above indicates that the waiting for connections
dbpath configuration is complete and MongoDB started successfully.
And now open the Explorer, into the DBPath directory of MongoDB, the content is as follows:
You can see that the database is actually initialized locally.
When creation succeeds, MongoDB pops up security warnings for Mongod.exe network traffic based on the system security level, chooses allow, and chooses a network, such as home and work network. More information on MongoDB security.
Running MongoDB
Start MongoDB by running Mongo.exe. For example:
The command-line window displays the following:
window, you can see the current version of the MongoDB shell, and the database that is connected at this time.
Note: If you want to develop your application using. NET, you can see the documentation for C # and MongoDB
start using MongoDB
To help you get started using Mongodb,mongodb provides a getting Started guide for various driver versions Getting Started Guides.
In the MongoDB shell, you help
can view the command description by:
Before you deploy MongoDB in a production environment, consider producing a production notes record file.
Finally want to stop MongoDB, you can use the Mongod.exe Command Line window, using the shortcut keys CTRL + C.
When the path in the box appears, MongoDB is stopped.
3 . Configuring Windows Services for MongoDB
In the above configuration, although the service is started and the database operation is possible, it is inconvenient to open two windows, so you can configure the Windows service through the configuration file.
Create a directory
Create a directory for your database and log files:
mkdir D:\MongoDB\data\dbmkdir D:\MongoDB\data\log
Create a CFG configuration file
To create a configuration file, the MongoDB log path Systemlog.path must be set within the file. The package expands some additional configuration options.
For example, D:\MongoDB\
create mongod.cfg under, and specify Systemlog.path and Storage.dbpath within the file:
Systemlog: destination:file path:d:\mongodb\data\log\mongod.logstorage: dbpath:d:\mongodb\data\db
Installing MongoDB Services
Attention:
Running all commands should be within the Administrator command Line window. (Administrator rights run cmd)
Install the MongoDB service by running Mongod.exe's –install installation options and –config and configuration options to specify the previously created profile.
"D:\MongoDB\bin\mongod.exe"--config "D:\MongoDB\mongod.cfg"--install
Set the standalone database address DBPath, which can be set by configuration file or command –dbpath.
If required, you can install multiple instances of the Mongod.exe or Mongos.exe service. Each installed service sets a unique –servicename and –servicedisplayname. Set multiple instances only when there is sufficient system resources and system design requirements.
To enable the service to start automatically, you can use the following command:
Sc.exe Create MongoDB binpath= "D:\MongoDB\bin\mongod.exe--service--config=\" C:\MongoDB\mongod.cfg\ "" Displayname= " MongoDB "start=" Auto "
In Sc.exe, a space is required between "=" and the configuration value (such as "BinPath ="), and a "\" is used to escape double quotation marks.
If created successfully, the following log information will be displayed:
[SC] CreateService SUCCESS
Open Service
net start MongoDB
shutting down and deleting services
Stop the MongoDB service using the following command:
net stop MongoDB
Delete the MongoDB service using the following command:
"D:\MongoDB\bin\mongod.exe"--remove
Of course you can use the. bat file to execute the above command in bulk.
"Set a small target first" Windows installs MongoDB 3.2