Thursday 8 November 2012

Setup MongoDB on Windows 8

Updated: 5th Oct 2014 with MongoDb version 3.0
Updated: 5th Oct 2014 with MongoDb version 2.6.4



This was surprisingly easy and worked straight off. This is a compressed version of the actual mongodb setup guide which is referenced below.

Mongo Version :            3.0
Windows Version :        Windows 8 64bit  / Windows 7 64bit

Step1 :  down load the Mongo Windows Version

Windows 64bit version  from  http://www.mongodb.org/downloads
I got a msi version and installed it in c:\mongodb\



Step2:  Create Directories

I used an explorer window, but you could use command prompt.

mkdir  c:\mongodb
mkdir  c:\mongodb\bin
mkdir  c:\mongodb\log
mkdir  c:\mongodb\data
mkdir  c:\mongodb\data\db


Step3: Copy Contents of ZIP to c:\mongodb (skip if you use msi installer)

I just dragged and dropped the file, will over right the bin directory.



Step 4: Create a Config file

C:\mongodb\mongod.cfg

contents

logpath=C:\mongodb\log\mongo.log
logappend=true
dbpath = C:\mongodb\data\db



Step 5: Create a Windows Service 

as per help page mongo

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

Step 6: Start the Service

net start MongoDB

THAT'S IT !!!!!

Quick Cheats Script


If you a tad (little) lazy like me you can just use the script below. Run a command prompt as Administrator and place the script below into a batch file like: goMondo.bat.  The script will create the directories, config file, install and start the service.


echo off
echo Here we Go, Creating MongoDB on Windows
echo Created by Frank Kerrigan see http://rundevrun.blogspot.co.uk
echo  Creating Base Directories
echo  ==========================
mkdir  c:\mongodb\log
mkdir  c:\mongodb\data
mkdir  c:\mongodb\data\db
echo Creating Mongdo Config File
echo ===========================
echo logpath=c:\mongodb\log\mongo.log > c:\mongodb\mongod.cfg
echo logappend=true >> c:\mongodb\mongod.cfg
echo dbpath=c:\mongodb\data\db >> c:\mongodb\mongod.cfg
echo Creating Windows Service
echo ========================
c:\mongodb\bin\mongod.exe --config c:\mongodb\mongod.cfg --install
echo Starting Mongo Service
echo ======================
net start MongoDB



Uninstall The Service


If you want to uninstall the MongoDB service, then stop it first. Open command prompt under Administrator.


c:\> sc delete MongoDB

Reference Doc

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/


C# Driver Quick Start

http://www.mongodb.org/display/DOCS/CSharp+Driver+Quickstart



See Post 2 in The Series

C# Simple Dal Layer With MongoDB

http://rundevrun.blogspot.co.uk/2014/10/c-simple-dal-layer-with-mongodb.html






6 comments:

  1. I get an error saying "The service name is invalid." when trying to start the service.

    ReplyDelete
  2. Nevermind, just had to run cmd as admin after chceking the logs.

    ReplyDelete
  3. Thank you for this post.

    ReplyDelete
  4. Excellent! worked like a charm!

    ReplyDelete
  5. Thanks, this was awesome

    ReplyDelete
  6. Hi,
    I am new to MongoDB. However, I could install successfully...
    Thanks....

    ReplyDelete

Comments are welcome, but are moderated and may take a wee while before shown.