Install MongoDB as a Windows Service

Installing MongoDB as a service on my Windows 7 turned out to be pretty simple. 

Download Mongo – http://www.mongodb.org/downloads

Follow Instructions – http://www.mongodb.org/display/DOCS/Windows+Service

There was one gotcha I ran into as I did the install.  If you specify an invalid data path the service will be stuck in an infinite loop of restarts, and have to be removed (or create the missing directory).

My install command :

   1: D:\Tools\MongoDB\mongodb-win32-x86_64-2.0.2\bin\mongod --logpath C:\Data\Development\logs\MongoDB.log --logappend --dbpath C:\Data\Development\MongoDB_Data --install --serviceName MongoDB


Here is the exception I was getting in my log file:

   1: ***** SERVER RESTARTED *****



   4: Sun Mar 04 10:20:08 [initandlisten] MongoDB starting : pid=6652 port=27017 dbpath=C:\Data\Development\OneBrownMule\OneBrownMule.Web\App_Data\AppDB 64-bit host=mueller-laptop2

   5: Sun Mar 04 10:20:08 [initandlisten] db version v2.0.2, pdfile version 4.5

   6: Sun Mar 04 10:20:08 [initandlisten] git version: 514b122d308928517f5841888ceaa4246a7f18e3

   7: Sun Mar 04 10:20:08 [initandlisten] build info: windows (6, 1, 7601, 2, 'Service Pack 1') BOOST_LIB_VERSION=1_42

   8: Sun Mar 04 10:20:08 [initandlisten] options: { dbpath: "C:\Data\Development\MongoDB_Data", logappend: true, logpath: "C:\Data\Development\logs\MongoDB.log", service: true }

   9: Sun Mar 04 10:20:08 [initandlisten] exception in initAndListen: 10296 dbpath (C:\Data\Development\MongoDB_Data) does not exist, terminating

  10: Sun Mar 04 10:20:08 dbexit: 

  11: Sun Mar 04 10:20:08 [initandlisten] shutdown: going to close listening sockets...

  12: Sun Mar 04 10:20:08 [initandlisten] shutdown: going to flush diaglog...

  13: Sun Mar 04 10:20:08 [initandlisten] shutdown: going to close sockets...

  14: Sun Mar 04 10:20:08 [initandlisten] shutdown: waiting for fs preallocator...

  15: Sun Mar 04 10:20:08 [initandlisten] shutdown: lock for final commit...

  16: Sun Mar 04 10:20:08 [initandlisten] shutdown: final commit...

  17: Sun Mar 04 10:20:08 [initandlisten] shutdown: closing all files...

  18: Sun Mar 04 10:20:08 [initandlisten] closeAllFiles() finished

  19: Sun Mar 04 10:20:08 dbexit: really exiting now

Tags :

Remove by Id–MongoDB C#

When removing a document by the identifier using the C# 10gen driver for MongDB you need to specify the internally used id column, “_id”, not the property name from the DTO that you’re storing.

The Driver can be found on NuGet by search for MongoDB or the official project github page can be found here.

   1: public class DataProvider 

   2: { 

   3:     private MongoDatabase _db;

   4:     public DataProvider() 

   5:     { 

   6:         var server = MongoServer.Create("mongodb://"); 

   7:         _db = server.GetDatabase("MyDB"); 

   8:     }

   9:     public void Delete(string id) 

  10:     { 

  11:         var collection = _db.GetCollection("MyDocumentCollection");

  12:         //Does not work 

  13:         //collection.Remove(new QueryDocument("Id", new BsonObjectId(id)));

  14:         //Works 

  15:         collection.Remove(new QueryDocument("_id", new BsonObjectId(id))); 

  16:     } 

  17: }

  18: public class MyDocument 

  19: { 

  20:     [BsonId] 

  21:     public ObjectId Id { get; set; } 

  22:     public string Name { get; set; } 

  23:     public string Description { get; set; } 

  24: }


I’ve submitted a pull request to have RemoveById added to the MongoCollection.


Tags : ,

What to Expect

When I decided that I wanted to start writing this blog I wanted to make sure that this wasn’t something that simply fizzled out after a couple of blog posts.  For me that meant setting expectations about what I will be blogging about and how frequently I will post new blogs.

What will I blog about

I’m a Software Architect developing large scale n-tiered business applications for the telecommunications industry.  Many of the business problems that I run into there don’t translate well into a readable blog, so I’ll likely stay away from those topics.  Some of the technical challenges I run into there are fairly interesting so I hope to translate those experiences into blog posts.

I manage a small business for my wife and myself.  That business does consulting, sales support, and maintains a counter top measuring application, written in .NET, for Laser Products.  This seems to be a good source of blog material for me.  Working with a client, getting feedback from customers, managing the business side of things, and working through the software development of this application are all things I plan on discussing here.

I’ve been married for a little over 5 years to my wife, Tracy, and we have two boys, Luke and Miles.  While there is no shortage of happenings in this area of my life, communicating these to the outside world seems much better suited for Facebook or Twitter.  These happenings may leak into this blog, but I’d expect them to be few and far between.  Follow me on Twitter or friend me in Facebook if you’re interested in learning more about this aspect of my life.

I wouldn’t call it a hobby, but there is one thing that I’ll stay up late or ignore the wife/kids for an opportunity to do, Cooking.  I love creating great food, and I love eating out (most likely because my daily meals involve timeouts and being climbed on by a two year old).  This defiantly has taken a back seat with the kids, but when I have the chance I still love to take a couple hours a cook a meal, or enjoy a dinner out with my wife. Things like meals that I’ve had or meals that I’ve created I plan on writing about here.

How often will I blog

I set a simple goal for my self regarding the frequency of my blog posts, one blog post every two weeks.  Managing my career, spending time with the family, and keeping the house together consume a considerable portion of my day, and all of those things are extremely important to me.  I figured that two posts a month shouldn’t disrupt those activities to much and still give me an opportunity to blog over 25 times during the first calendar year.  Who knows, maybe I’ll surprise myself and post these blogs more frequently.


A couple weeks back I decided that I am going to try and step outside my comfort zone and attempt to improve my written communication skills.  I thought about this for a little while and decided the best course of action for that would be to:

  1. Purchase a web domain and a hosting package
  2. Set up a blog on the newly created web site
  3. Create several pages to help my online presence
  4. Post a blog every two weeks

The first portion was pretty simple.  Navigate to GoDaddy.com and purchase a URL and some hosting.  GoDaddy makes it pretty simple and I’ve been purchasing URLs from them for several years so it was a pretty easy process.

Setting up the blog was a little more difficult.  The hosting package that I purchased from GoDaddy allowed me to pretty easily configure a WordPress blog and get it up and running, but there were several tweaks that were then needed.

  1. Find a theme that I like (found mine here)
  2. Install the theme on my web server
  3. Modify the header and footer with my personal information 
    1. Add author tags (thank you Scott Hanselmen – authorship)
    2. Modify the copywrite information
  4. Ensure that I can post to the site with ease

By far this last step was the most difficult.  I wanted to be able to write my articles while offline and then post them onto the website.  A quick search netted me Window Live Writer as a offline blog editing tool.  Because I’m a software developer much of this blog will be related to my experiences there so I wanted to ensure I could share code by publishing to the blog.  That required a SyntaxHighligher WordPress plugin to be downloaded locally, ftp’ed it up to the webserver, and then activated in the addins dashboard for the blog site.  Finally I needed Windows Live Writer to be able to let me add code content.  That required searching the internet and finding the PreCode Snippet addin which handles this portion nicely.

Now that I have the website up and running I’ll be able to focus on my original goal of writing and publishing that content.

Tags : ,