WebFund 2013W: MongoDB

From Soma-notes
Revision as of 15:16, 1 March 2013 by Soma (talk | contribs)
Jump to navigation Jump to search

In this tutorial you will start playing with MongoDB.

Note: MongoDB has its own JavaScript interpreter. Thus, in a web application using Node and MongoDB you'll have three JavaScript interpreters: the one in the browser, the one in Node, and the one in MongoDB. Same language, but access to different resources/objects in each.

You should try to get through all of this tutorial, up to the "Learning More" part. In particular, your aim should be to learn enough about MongoDB so you can understand how our blog example works well enough so you can add extra functionality.

Interactive Tutorial

First, for a gentle introduction, try this interactive MongoDB tutorial. It is very simple but will get you familiar with the basics.

Get MongoDB running

To get MongoDB running in Ubuntu, just run apt-get install mongodb.

On Windows, follow the instructions here. (Note: you can't get it to run as a service in the lab.)

For every other operating system, refer to the MongoDB Getting Started guides.

Use your installed MongoDB

Do the regular getting started tutorial in your now up-and-running MongoDB installation. Note there is some overlap with the Interactive Tutorial.

Node and MongoDB

Recall that we covered a Node app that used MongoDB in the simple blog tutorial. A slightly revised version of the code (more in keeping with current versions of Node) is available here.

Can you now get comments working in the blog example? What did you need to change? Note that most of the database access code needed is already in the program.

For an extra challenge, add tags to posts.

Learning more

To learn more about MongoDB, try out other tutorials.

To learn more about how Node and MongoDB interact, see the documentation of the MongoDB driver for Node.

If you want to interact with MongoDB at a higher level in Node, mongoose may be of interest.