Skip to content
Matt Styles edited this page Jun 22, 2013 · 5 revisions

The mongo branch adds a mongo database and organises some of the server-side code better.

Use Example

As usual, to get up and running with a mongo database follow these steps to get started with a project called awesome-project:

git clone git@github.com:mattstyles/yeoman-angular-express-plus awesome-project && cd $_
git checkout mongo
npm install
grunt dev --use-server

These commands clone the master repository into /awesome-project/ and gets cracking installing the required dependencies to start the Grunt task that will actually bootstrap the project seed into life.

The first time grunt is run it will run the install task which will perform a couple of different initialisation tasks including installing components using bower so expect this step to take a minute or so (depending on your connection speed).

Once the install task has run it will perform a development build of the project and fire up the local node server, sometimes the browser will open before the server, if this happens and you get a connection error then just hit refresh, if it still doesn’t work then check that the server has actually started and if it still doesn’t work then file an issue.

At this point you have full control of git but the install task has stripped the remote so you are no longer tied to the seed repository and should register your own remote. Create a new repository in github and add it as a remote:

git remote add origin git https://github.com/your-username/awesome-project.git

Now that your project is setup with git it’s time to get exploring and developing with it.

If it’s still running in the browser then have a play with the simple example page. The socket test button should turn the hero unit red after a quick exchange with the server and the route test button should provide a response from the server but, unless you have left a local instance of MongoDB running you’ll see that hitting the database test button will cause it to hang (this is a known issue although the server will report if it failed to connect at start-up).

To fix this you’ll need to get a local instance of MongoDB up and running and populated with some very basic test data.

Installing MongoDB

A detailed install guide for Mongo can be found here. The following are instructions for installing on OS X ( > 10.6).

The recommended method for installing Mongo is via Homebrew, if you don’t already have Homebrew then get it:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

If you’ve already got homebrew then make sure it is up-to-date:

brew update

Now let Homebrew do it’s thing and get MongoDB installed:

brew install mongodb

If there are any problems with the install then consult the Mongo install guides as you’ll get far more joy than filing an issue.

Firing up Mongo

If the install went correctly then Mongo should now be available at the the command line so open up a terminal window and hit up:

mongod

This will fire up Mongo. If you now try the database test button in the browser (grunt dev --use-server is still running right?) then you should be getting a response from the database.

Creating data

Hang on! How did the database return a response? Where is it getting data from?

Don’t worry, to save an additional step server/db/index.js will create a dummy collection and use that when the server/db/example.js route is hit. Don’t believe me? Ok, access the mongo shell:

mongo

Now have a look at the databases in Mongo:

show dbs

Amongst the databases (if you just installed there shouldn’t be any) you'll see test_db. If you followed these instructions closely then the project will have created that database (and the collection within it) when the server started and it got the name from the app-config.json file.

Now go get creating some cool stuff using a database! Have a look through the other use-cases for examples using goodies from the other branches.


Fin

Clone this wiki locally