Preparing your Windows box for AWS and a MEAN (Node) website: Install MongoDB as a Windows Service

Joseph Nielsen
5 min readSep 15, 2016

--

I walk through step by step how to get the Node.JS MEAN.JS scaffolded site working on a Windows 10 machine. This section is about installing MongoDB on your local machine.

Next, let’s install MongoDb so that we can run the app locally before publishing to AWS.

Click Download

Click download on the top right.

Select Windows Server 2008 R2 64-bit and later, with SSL support from the drop down

Download and run the Windows installer for Windows Server 64 bit with SSL Support

for (;1 < 2;) console.log(‘Next’);

Click Next on the first screen of the installer.

Genuflect the I accept and then hit next

Click I accept and then Next.

Click Complete. Mongo, you Complete me.

Click Complete

Install. Medieval Times and Install buttons on Windows. Two things that have shields.

Click Install and then Yes if you are prompted by Windows User Account Control.

Finish him!

Easy. The installer is done.

Great! Now we have all the necessary software installed to see things running locally and publish to the cloud. Let’s take care of some minor configuration needed in MongoDb.

Configure MongoDb as a Windows Service

MongoDB has wonderful documentation. I’ll be following the steps posted here.

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

I’m going to skip down to the section titled: Configure a Windows Service for MongoDB Community Edition

In our bash admin prompt, let’s create some data directories.

cd c:mkdir datacd datamkdir dbmkdir log
create your data folder with db and log folders inside

Let’s now set the configuration file in mongodb.cfg

Let’s navigate to where we installed MongoDb.

cd "program files"cd mongodbcd servercd 3.2cd bin
Use the ls or pwd commands if you get lost- or “cd” + TAB key

(Use the “ls” command to list the contents of the folder if you need to)

To create the configuration file we’ll type vi mongodb.cfg and press enter.

vi mongodb.cfg

Hit the “i” key to start typing. When you’re done typing hit the “ESC” key followed by typing “:wq” and then Enter.

Our file should look like this. It’s very important that the beginning of each line should be started with two spaces and not a tab character. This is called “yaml” format.

systemLog:
destination: file
path: c:\\data\\log\\mongod.log
storage:
dbPath: c:\\data\\db
Don’t forget, it’s YAML format. Each tab should be replaced by two spaces.

VI tip: To enter typing mode press “i” and then begin typing. To save the file hit the “ESC” key and then type “:wq” to write the file and then quit. If you ever need to quit the vi text editor without saving, type “:q!”

Now that your configuration file is saved you are good to try running the mongo service.

Let’s run mongod.exe

./mongod.exe
mongod.exe. The d is for daemon. Worker process not The Golden Compass.

Great. You’re prompted to allow access through the firewall.

Check both boxes and select “Allow access”

Select both check boxes and click Allow access.

Hit CTRL+C to break out of there and go back to the dollar sign and blinking cursor.

If you didn’t hit CTRL+C to exit, there will be an error message at the end of this flibbity-gibbet

This means that the install works. If you didn’t have to use CTRL+C to exit back to Git Bash, then that means you may have something wrong that caused the service to exit. Double check that your c:\data\db and c:\data\log directories exist and that you have run bash with administrator permissions. (Right click the bash program on the bottom bar, then right click “Git Bash” and select “Run as administrator”)

Now you should be back to our friend the blinking cursor, the prompt.

Type this mongod -config command to install the windows service.

./mongod.exe --config "c:\program files\mongodb\server\3.2\bin\mongodb.cfg" --install

If you’ve received the below error, perhaps you’ve entered a wrong value like me in your mongodb.cfg file

Error parsing YAML config file: yaml-cpp: error at line 2, column 13: illegal map valuetry ‘C:\program files\mongodb\server\3.2\bin\mongod.exe — help’ for more information

Double check that you are indenting your lines with two spaces instead of any tab characters.

Next I start the mongodb service with this net start mongodb command

net start mongodb
“net start mongodb” is the window’s version of “sudo service mongodb start”

Mongodb is good to go.

(Keep in mind that Mongodb allows anonymous access by default. You must secure this either through IAM and security group policies in AWS or by disabling anonymous authentication.)

Unlisted

--

--

Joseph Nielsen

I lead the software engineering and DevOps practice for Slalom, New Jersey. I enjoy building things, endurance running and all things DeepRacer.