-
Notifications
You must be signed in to change notification settings - Fork 1.7k
DOCS-155 Windows Installation Tutorial #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
========================== | ||
Install MongoDB on Windows | ||
========================== | ||
|
||
.. default-domain:: mongodb | ||
|
||
Synopsis | ||
-------- | ||
|
||
This tutorial outlines the basic installation process for | ||
:term:`MongoDB` on Microsoft Windows systems. This | ||
tutorial provides a basic method for installing and running the | ||
MongoDB server (i.e. ":program:`mongod.exe`") and associated tools. | ||
|
||
MongoDB for Windows | ||
------------------- | ||
|
||
MongoDB for Windows is very similar to it MongoDB for other | ||
platforms. MongoDB components work in the same way and with similar | ||
parameters to MongoDB for other platforms. This tutorial will guide | ||
you to install MongoDB on Windows through the :guilabel:`Command | ||
Shell` and setting up MongoDB as a :guilabel:`Windows Service`. | ||
|
||
Download MongoDB for Windows | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Download the latest production release of MongoDB from `here. <http://www.mongodb.org/downloads>`_ | ||
|
||
.. note:: | ||
|
||
Ensure you download the proper version of MongoDB for your | ||
architecture of Windows. The 64-bit version of MongoDB will not | ||
work in 32-bit Windows. | ||
|
||
The 32-bit versions of MongoDB are suitable for testing and | ||
evaluation purposes but cannot use databases larger than 2GB. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this is not technically wrong (agreed, you cannot use databases larger than 2GB) it implies that you are OK up to 2GB. In fact, because MongoDB memory-maps all database files into contiguous regions of user-mode address space, you can run into trouble well below 2 GB of data. It would be less misleading to replace "but cannot use databases larger than 2GB" with "but are limited to small databases". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. amended the note. |
||
|
||
The architecture of your version of Windows can be found using this | ||
command in the :guilabel:`Command Shell` | ||
|
||
.. code-block:: powershell | ||
|
||
wmic os get osarchitecture | ||
|
||
In Windows Explorer, find the MongoDB download file, typically in the | ||
default Downloads directory, and extract the archive to ``C:\`` by | ||
right clicking on the archive and selecting :guilabel:`Extract All` | ||
and browsing to: ``C:\`` | ||
|
||
.. note:: | ||
|
||
The folder name will be either: | ||
|
||
.. code-block:: powershell | ||
|
||
C:\mongodb-win32-i386-[version] | ||
|
||
Or: | ||
|
||
.. code-block:: powershell | ||
|
||
C:\mongodb-win32-x86_64-[version] | ||
|
||
In both examples, replace ``[version]`` with the version of MongoDB | ||
downloaded. | ||
|
||
Set up the environment | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Start the :guilabel:`Command Shell` by selecting the :guilabel:`Start | ||
Menu`, then :guilabel:`All Programs`, then :guilabel:`Accessories`, | ||
then right click :guilabel:`Command Shell`, and select :guilable:'Run | ||
as Administrator' from the popup menu. In the :guilabel:`Command Shell`, | ||
issue the following commands: | ||
|
||
.. code-block:: powershell | ||
|
||
cd \ | ||
rename C:\mongodb-win32-* C:\mongodb | ||
|
||
.. note:: | ||
|
||
MongoDB is self-contained and do not have any other system | ||
dependencies. You can run MongoDB from any folder you choose. One | ||
may install MongoDB in a different directory such as: | ||
``D:\test\mongodb`` | ||
|
||
By default, MongoDB requires a data folder to store files. By default | ||
this is: ``C:\data\db``. Create this folder in ``C:\`` in the | ||
:guilabel:`Command Shell` by issuing the following commands | ||
|
||
.. code-block:: powershell | ||
|
||
mkdir data | ||
mkdir data\db | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but the usual Windows/DOS command is "md". "mkdir" is the Unix/Linux command and also works on Windows. So, idiomatically, "md" is better for Windows. You can also specify the driver letter in the command, so "md C:\data" (etc.) might be a better example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it! |
||
|
||
.. note:: | ||
|
||
You can specify an alternate path for data\db folder using the | ||
:option:`--dbpath <mongod --dbpath>` option to | ||
:program:`mongod`. To start mongod.exe with another file path, use | ||
the command: | ||
|
||
.. code-block:: powershell | ||
|
||
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mention the need for quotes around paths and filenames that includes spaces. e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check |
||
|
||
|
||
Start MongoDB for Windows | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
To start MongoDB, execute from the :guilabel:`Command Shell`: | ||
|
||
.. code-block:: powershell | ||
|
||
C:\mongodb\bin\mongod.exe | ||
|
||
This will start the main MongoDB database process. | ||
|
||
.. note:: | ||
|
||
Depending on the security level of your system, Windows will issue | ||
a :guilabel:`Security Alert` dialog box about blocking "some | ||
features" of ``C:\\mongodb\bin\mongod.exe`` from communicating on | ||
networks. All users should select ``Private Networks, such as my | ||
home or work network`` and click ``Allow access``. For additional | ||
information on security and MongoDB, please read the | ||
:wiki:`Security and Authentication <Security+and+Authentication>` | ||
wiki page. | ||
|
||
.. warning:: | ||
|
||
Do not make :program:`mongod.exe` accessible to public networks | ||
without authentication (i.e. :setting:`auth`) on a public | ||
network. MongDB is designed to work within secured networks and | ||
will accept connections without authentication. | ||
|
||
To connect to MongoDB using the :program:`mongo.exe`, open another | ||
:guilabel:`Command Shell` and issue command: | ||
|
||
.. code-block:: powershell | ||
|
||
C:\mongodb\bin\mongo.exe | ||
|
||
.. note:: | ||
|
||
Executing command: ``start C:\mongodb\bin\mongo.exe`` will | ||
automatically start MongoDB in a separate :guilabel:`Command Shell`. | ||
|
||
This will connect to the database running on the localhost interface | ||
and port ``27017`` by default. At the :program:`mongo.exe` prompt, issue | ||
the following two commands to insert a record in the ``test`` | ||
:term:`collection` of the default ``test`` database and then retrieve | ||
that record: | ||
|
||
.. code-block:: javascript | ||
|
||
> db.test.save( { a: 1 } ) | ||
> db.test.find() | ||
|
||
.. seealso:: ":program:`mongo`" and ":doc:`/reference/javascript`" | ||
|
||
|
||
MongoDB as Windows Service | ||
-------------------------- | ||
|
||
.. versionadded:: 2.1.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure of the first version with Windows service support, but mongod.exe had it in 2.0. mongos.exe got this support more recently, maybe in 2.1.1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to leave this in for the moment. We were only able to confirm this process, for 2.1, as the process for getting it working on the wiki was somewhat less than clear on the service-related features in 2.0. We can touch base on it in the morning. |
||
|
||
Setup MongoDB to be a :guilabel:`Windows Service`, starting | ||
automatically with each reboot. | ||
|
||
Configure Windows Service Options | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
You must specify two options when running MongoDB as a Windows | ||
Service: a directory for the log output and a :doc:`configuration file | ||
</reference/configuration-options>`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A config file is not a requirement for running as a Windows service, but it probably makes it easier to manage (because you can just edit the external file and not mess with the settings of the Windows service itself). --logpath is required, because without it all log output would go nowhere. logpath could be specified in the config file if desired. Also, --logappend is pretty valuable, especially with versions below 2.2, so you don't clobber existing log files with every restart. Version 2.2 will automatically "logRotate" if started without --logappend and the log file already exists. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm inclined to limit the explination of this behavior right here because it can confuse, and this is meant to be a "quickstart" guide and not terribly detailed. Do you know if the logrotate by default is windows specific or across all platforms? I think we should definitely sync up tomorrow to make sure the documentation will reflect this change. |
||
|
||
#. Create a specific directory for MongoDB log files: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a requirement. If this is a walkthrough of a particular install, this is fine, but you can put log files anywhere you want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check. |
||
|
||
.. code-block:: powershell | ||
|
||
mkdir C:\mongodb\log | ||
|
||
#. Create a configuration file for the logpath option for MongoDB in | ||
the :guilabel:`Command Shell` by issuing this command: | ||
|
||
.. code-block:: powershell | ||
|
||
echo logpath=C:\mongodb\log > C:\mongodb\mongodb.cfg | ||
|
||
|
||
To Install and Run the MongoDB Service | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Run all of the following commands in :guilabel:`Command Shell` with | ||
"Administrative Privileges:" | ||
|
||
#. To install the MongoDB service: | ||
|
||
.. code-block:: powershell | ||
|
||
C:\mongodb\bin\mongod.exe --config C:\mongodb\mongodb.cfg --install | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we shooting for brief, or complete? You can specify the service name, service "display name" and service description if you feel like it. Not worth mentioning if "brief" is the goal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. brief is the goal here: there'll be another document for running MongoDB in a more production-like context. |
||
|
||
#. To run the MongoDB Service: | ||
|
||
.. code-block:: powershell | ||
|
||
net start MongoDB | ||
|
||
To Stop or Remove the MongoDB Service | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
#. To stop MongoDB Service: | ||
|
||
.. code-block:: powershell | ||
|
||
net stop MongoDB | ||
|
||
#. To remove MongoDB Service: | ||
|
||
.. code-block:: powershell | ||
|
||
C:\mongodb\bin\mongod.exe --remove | ||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to it" => "to"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got this one