We are going to learn how to download, install, and run MongoDB on a computer running on Windows:
1. Head on over to the downloads page on the MongoDB official website, http://www.mongodb.org/downloads.
2. Click on the download link for the latest stable release under Windows 32-bit. This will start downloading a ZIP archive:
3. Once the download is finished, move the ZIP archive to the
C:\
drive and extract it. Rename the extracted folder (mongodb-win32-i386-x.y.z wherex.y.z
is the version number) tomongodb
.4. Create the folder
C:\data\db
. Open a CMD prompt window, and enter the following commands:C:\> cd \mongodb\bin C:\mongodb\bin> mongod
5. Open another CMD prompt window and enter the following commands:
C:\> cd \mongodb\bin C:\mongodb\bin> mongo
6. Type
show dbs
into the shell and hit Enter.
In steps 1 to 3, we downloaded and extracted a ZIP archive that contains binary files for running MongoDB on Windows, moved and extracted it under the C:\
drive, and renamed the folder to mongodb
for convenience. In step 4, we created the data directory (C:\data\db). This is the location where MongoDB will store its data files. In step 5, we execute the C:\mongodb\bin\mongod.exe
program in the CMD prompt to launch the MongoDB server; this is the server that hosts multiple databases (you can also do this by double-clicking on the file in Windows Explorer). In step 6, after the server program is booted up, we invoke the C:\mongodb\bin\mongo.exe
program to start the mongo interactive shell, which is a command-line interface to the MongoDB server:
C:\mongodb\bin\mongo MongoDB shell version: 1.8.1 connection to test type "help" for help >
Once the shell has started, we issue the command show dbs
to list all the pre-loaded databases in the server:
>show dbs admin (empty) local (empty) >
The documentation at the MongoDB website recommends that you run the 64-bit version of the system. This is because the 32-bit version cannot store more than 2 gigabytes of data. If you think it is likely that the data in your database will exceed the 2 GB limit, then you should obviously download and install the 64-bit version instead. You will also need an operating system that supports running applications in the 64-bit mode. For the purpose of the practical examples shown in this book, we are just fine with the 32-bit version, you should not worry about that too much.