Install MongoDB in Windows

Source: Internet
Author: User
Tags download mongodb for windows install mongodb mongodb documentation mongodb download mongodb version mongodb windows
1. SummaryThis article describes how to install and run the mongodbserver (“mongomongod.exe ") on Microsoft Windows and set it to a Windows service. Using MongoDB on Windows is similar to using MongoDB on other platforms. Most components share the same operation mode. 2. Steps (1) download MongoDB for Windows Download the latest MongoDB version from the MongoDB download page. MongoDB has three Windows Versions:
  • MongoDB Windows Server 2008 R2 (2008r2) is only applicable to Windows Server 2008 R2, Windows 7 64-bit, and newer versions. this version utilizes the latest enhancements of the Windows platform and cannot be used in earlier Windows versions.
  • The 64-bit version of MongoDB for Windows is applicable to any 64-bit Windows versions newer than Windows XP, including Windows Server 2008 R2 and Windows 7 64-bit.
  • MongoDB's windows 32-bit version is applicable to any 32-bit Windows version newer than Windows XP. MongoDB's windows 32-bit version is only applicable to old systems and test and development systems.
Note:: Always download the correct version for your Windows system. MongoDB's windows 64-bit version cannot be used in Windows 32-bit systems.

MongoDB's windows 32-bit version is only applicable for testing and evaluation purposes and only supports databases smaller than 2 GB.

You can run the following command on the command line to view the architecture of your Windows platform:

                wmic os get osarchitecture
Find the downloaded MongoDB file in the Windows resource manager, and usually decompress it to "C: \" under the default downloads directory :\".
               Note:: The folder name is c: \ mongodb-win32-i386-[version] or c: \ mongodb-win32-x86_64-[Version], replace [version] with the version number of the MongoDB you downloaded.
          (2) build an environment
          Start the command line and execute the following command:
     cd \     move C:\mongodb-win32-* C:\mongodb

Note:: MongoDB is independent and has no other system dependencies. You can run MongoDB from any folder you choose. You can install MongoDB in any directory (for exampleD: \ test \ MongoDB)

MongoDB needs a data folder to store its files. The default data folder path isC: \ data \ DB. You can use the command line to create this folder. Execute the following commands in sequence:

     md data     md data\db

Note:: You can runMongod.exeSpecify the dbpath parameter to replace\ Data \ dB path, As follows:

                 C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data

If your path contains spaces, you can use double quotation marks to include the entire path. For example:

                 C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"
(3) Start MongoDB
Run the following command in the command line to start MongoDB:
      C:\mongodb\bin\mongod.exe

This will start the primary process of the MongoDB database. Console outputWaiting for connectionsThe message indicates that the mongod.exe process is successfully running.

Note:: According to the security level of your system, Windows will pop up a security alarm dialog box to prevent some functions of C: \ MongoDB \ bin \ mongod.exe from communicating over the network. All users should select a private network, such as my home or work network, and click "Allow access ". For more information about MongoDB security, see the security practices and management page.

Warning: If it is not running in security mode (that isAuth.), Do not allow public network accessCmdd.exe.MongoDB is designed for trusted environments and the database does not enable authentication or security mode by default.

UseCmd.exeShell connects to MongoDB. Open another command line window and execute the following command:

      C:\mongodb\bin\mongo.exe

Note:: ExecutionStart c: \ MongoDB \ bin \ cmd.exeThe command is automatically started in another command line window.Cmd.exeShell.

Cmd.exeShell will connect to the local interface and the defaultPort 27017 Mongod.exe. InCmd.exeWindow,
Run the following two commandsTestInsert a record in the test set of the database and retrieve the record:

      > db.test.save( { a: 1 } )      > db.test.find()

See"MongoAndMongo
Shell JavaScript Quick Reference
. "If You Want To use. Net to develop applications, see the C # And MongoDB documentation for more information.

3. MongoDB as a Windows Service

Set MongoDBA service in WindowsIn this way, the database will be automatically started as the system starts.

Note::Mongod.exeAdded support for Windows Services in version 2.0,
Mongos.exeAdded support for Windows Services in version 2.1.1.

(1) System Configuration

When MongoDB runs as a Windows Service, two options should be set: One log output path (that isLogpath)
And a configuration file.

1. Create a specified directory for the MongoDB log file:

MD c: \ MongoDB \ log

2. Run the following command in the command line Create a configuration file using logpath: Echo logpath = c: \ MongoDB \ log \ Mongo. Log> C: \ MongoDB \ mongod. cfg

Although these steps are optional, it is a good practice to create a specified path for the log file and use the configuration file.

Note:: You can consider settingLogappend.
If not,Mongod.exe will delete the content of the existing log file at startup. 

(2) install and run the MongoDB Service

Run the following command on the command line with administrator privileges:

1. Install the MongoDB service:

        C:\mongodb\bin\mongod.exe --config C:\mongodb\mongod.cfg --install

You can modify it if needed.Path of the d. cfg file. To enable -- InstallOption,
You must specifyLogpathSet or-- LogpathRuntime options.

2. Run the MongoDB service:

Net start MongoDB

Note:: If you want to replace yourDbpath, which can be -- InstallThe configuration file specified in the operation (that isC: \ MongoDB \ mongod. cfg. You can also specify-- Dbpath,
However, configuration files are always the best choice.

IfDbpathDirectory does not exist,Mongod.exeWill not start.DbpathThe default value is\ Data \ DB.

(3) Stop or delete the MongoDB Service
  • Stop MongoDB service:

     net stop MongoDB
  • Delete MongoDB service:

    C:\mongodb\bin\mongod.exe --remove


Note: This article is translated from http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/. if you have any questions, please correct them.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.