MongoDB Windows Installation

  • How to install and start MongoDB PC?

MongoDB is an open resource available on the internet. If MongoDB is not installed in computer, we have to download and install it from MongoDB official website http://downloads.mongodb.org.

Guidance for Windows

We typed in command prompt

>wmic os get osarcitecture

Result of this command showed the architecture of OS (whether it is 32bit or 64bit). Depending on OS architecture,we downloaded MongoDB from the above mentioned website. There are three builds of MongoDB for Windows.

  1. MongoDB for Windows Server 2008 R2 edition (i.e. 2008R2) only runs on Windows Server 2008 R2, Windows 7 64-bit, and newer versions of Windows. This build takes advantage of recent enhancements to the Windows Platform and cannot operate on older versions of Windows.
  2. MongoDB for Windows 64-bit runs on any 64-bit version of Windows newer than Windows XP, including Windows Server 2008 R2 and Windows 7 64-bit.
  3. MongoDB for Windows 32-bit runs on any 32-bit version of Windows newer than Windows XP. 32-bit versions of MongoDB are only intended for older systems and for use in testing and development systems. 32-bit versions of MongoDB only support databases smaller than 2GB.

So, choosing particular version which meets OS configuration MongoDb-win32 downloaded.

Then we extracted the .zip fie and rename the folder to MongoDB (optional). Also it is done by issuing command like,

cd \

move C:\mongodb-win32-* C:\mongodb

  • Note: We can run MongoDB from any folder

Important!: As we are running edition of Windows Server 2008 R2 or Windows 7,we installed a hotfix to resolve an issue with memory mapped files on Windows6.

Okay, now MongoDB is installed in computer. Next step is to set data repository i.e. a folder required by MongoDB to store it’s files. The default location for the MongoDB data directory is C:\data\db.We created this folder using the Command Prompt in following command sequence:

md data

md data\db

We can also specify an alternate path for data files using the –dbpath option to mongod.exe.

Everything has been set up properly now it’s time to start and test MongoDB.

Start and Connect MongoDB

To start MongoDB,we executed from the Command Prompt:

C:\users\username>cd\

C:\cd mongodb

C:\mongodb>cd bin\

C:\mongodb\bin>mongod

OR

C:\mongodb\bin\mongod.exe

OR

Also we typed mongod in RUN (Window key + R) and hit Enter Key

This started the main MongoDB database process. The “waiting for connections on port 27017” message in the console output indicates that the mongod.exe process or Mongo Server is running successfully.

Well, MongoDB server is running. Now to Connect to MongoDB using the mongo.exe shell we openned another Command Prompt and issued the following commands:

C:\users\username>cd\

C:\cd mongodb

C:\mongodb>cd bin\

C:\mongodb\bin>mongo

OR

C:\mongodb\bin\mongo.exe

OR

We also typed mongo in RUN (Window key + R) and hit Enter key which was successful

The mongo.exe shell will connect to mongod.exe running on the localhost interface and port 27017 by default.

At the mongo.exe prompt, issue the following two commands to insert a record in the test collection of the default test database and then retrieve that record:

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

>db.test.find()

and the corresponding result will be ,

{ “_id” : ObjectId(“5379f8a9a59a941c998ccca2”), “a” : 1 }

the ObjectId may be different for different computer or system.

This ensured that connection to mongo shell is successful. We also checked it from mongo server or mongod shell. A message appeared like ‘(1 new connection open)’ in mongo server.

Leave a Reply

Your email address will not be published. Required fields are marked *