======== cited text =======
Over the last few months there’s been an increasing amount of interest in NoSQL database options among the members of the PHP Developers’ Group that I help organize in Chattanooga … and frankly, I’ve been itching to dig in myself. The other organizers and I decided that what we would do is each choose a NoSQL database engine, and over the next few months we’d cover those engines by devoting the main presentation of a meeting to them. Our presentations will cover the basics of using the engine in question, discuss the strengths and weaknesses of the engine, and the process of building a simple a simple application in PHP with it.
I chose MongoDB. Well, as fate would have it, I was in the process of learning ASP.NET/C# at work, and as an exercise, I ended up setting up MongoDB on Windows and using it to build a simple web using ASP.NET … so my first foray into MongoDB was with C# rather than PHP. Go figure.
MongoDB works quite well on Windows. Unfortunately, the downloadable .ZIP package you get from mongodb.org doesn’t give you any indication of how to run it as a Windows service, and I really, really wanted to do that instead of having to manually start it up every time I wanted to play with it. I went out searching for information on how to do so, and ended up finding conflicting instructions that sometimes didn’t work. I couldn’t find any start-to-finish tutorial that explained all the steps of how to get things working. Hence this post …
In this tutorial, I’m using what is currently the most recent production-ready version of Mongo, 1.4.1. You should be vaguely comfortable with working with the command prompt, editing registry entires with regedit, and starting/stopping services before going any further. You may break your computer, anger your mailman or trigger an IRS audit if you’re not careful. You’ve been warned. Finally … I have no idea if these instructions work on any other version of Windows; I haven’t tried them on anything but Windows 7.
- Download and extract the MongoDB archive appropriate for your system. http://www.mongodb.org/display/DOCS/Downloads
- Copy the extracted folder to C: and rename it mongo.
- Create a directory called ‘data’ inside C:mongo
- Click on the Start Menu and enter “cmd” in the search box. Right-click on cmd.exe and select “Run as administrator.” This is VERY important because you won’t be able to register MongoDB as a service if you run cmd.exe with normal privileges.
- Type “C:mongobinmongod –install” to register MongoDB as a Windows service. This will probably output what may look like an error message, but don’t worry … as long as you really did run cmd.exe with administrator privileges, everything is fine.
- Click on the start menu and enter “regedit” in the search box. Click on regedit.exe, and then browse to HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservices. There should be child folder there named MongoDB that has several keys inside it. If not, go back to step 4 and try again.
- The ImagePath key should read “c:mongobinmongod –service” right now; change it to “c:mongobinmongod –service –dbpath c:mongodata”. This will allow MongoDB to find its data files.
- Click on the Start Menu and enter “services” in the search box. Click on the “Component Services” option.
- In the pane on the far left, double-click on “Services (Local).” Locate MongoDB in the list in the center pane, and double click on it to bring up the properties inspector window.
- Make sure “Startup type” is set to automatic. Then click on the “Start” button.
- Browse to http://localhost:28017/ to verify that MongoDB is really running.
======== cited text =======/