WebFund 2013W: MongoDB: Difference between revisions

From Soma-notes
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:


'''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.
'''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===
===Interactive Tutorial===
Line 11: Line 13:
To get MongoDB running in Ubuntu, just run <tt>apt-get install mongodb</tt>.
To get MongoDB running in Ubuntu, just run <tt>apt-get install mongodb</tt>.


On Windows, follow the instruction [http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/].  (Note: you can't get it to run as a service in the lab.]
On Windows, follow the instructions [http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/ here].  (Note: you can't get it to run as a service in the lab.)


For every other operating system, refer to the MongoDB  [http://docs.mongodb.org/manual/tutorial/ Getting Started guides].
For every other operating system, refer to the MongoDB  [http://docs.mongodb.org/manual/tutorial/ Getting Started guides].


===More MongoDB tutorials===
===Use your installed MongoDB===
 
Do the [http://docs.mongodb.org/manual/tutorial/getting-started/ regular getting started] tutorial in your now up-and-running MongoDB installation.  Note there is some overlap with the Interactive Tutorial.  If you find this boring, skip to the next part.
 
===Node and MongoDB===


Do the [http://docs.mongodb.org/manual/tutorial/getting-started/ regular getting started] tutorial in your now up-and-running MongoDB installation.
Recall that we covered a Node app that used MongoDB in the [[WebFund_2013W:_Task_2|simple blog tutorial]].


To keep going, try out [http://docs.mongodb.org/manual/tutorial/ other tutorials]! But, these are probably more than you need until you have your basic application working.
You have now learned enough background that [http://howtonode.org/express-mongodb this tutorial on making a simple blog] that we previously covered should make a lot more sense. Note that this tutorial is based on an older version of Node; a slightly revised version of the code (more in keeping with how we've been using express in class) is available [http://homeostasis.scs.carleton.ca/~soma/webfund-2013w/blog-updated.zip here].  (Don't forget to run <tt>npm install</tt> after unpacking!)


===Node and MongoDB===
This version of the code follows the tutorial up until around where comments are added.  Start reading the tutorial from the beginning and follow along in the code in <tt>blog-updated</tt>.  Finish the blog example by adding the necessary code, style sheets, and templates to implement a simple commenting system.  (Some of this code is already present.)
 
If doing that is too easy, add tags to the posts!  That will require you to both change the appearance of the application and change what is stored in MongoDB.
 
===Learning more===


Recall that we covered a Node app that used MongoDB in the [[WebFund_2013W:_Task_2|simple blog tutorial]].  A slightly revised version of the code (more in keeping with current versions of Node) is available [http://homeostasis.scs.carleton.ca/~soma/webfund-2013w/blog-updated.zip here].
To learn more about MongoDB, try out [http://docs.mongodb.org/manual/tutorial/ other tutorials].


Can you now get comments working in the blog example?  What did you need to change?
See Chapter 10 of [http://shop.oreilly.com/product/0636920024606.do Learning Node] for an introduction to Node and MongoDB.


To learn more about how Node and MongoDB interact, see the [http://mongodb.github.com/node-mongodb-native/ documentation of the MongoDB driver for Node].
To learn more about how Node and MongoDB interact, see the [http://mongodb.github.com/node-mongodb-native/ documentation of the MongoDB driver for Node].


If you want to interact with MongoDB at a higher level in Node, [http://mongoosejs.com/index.html mongoose] may be of interest.
If you want to interact with MongoDB at a higher level in Node, [http://mongoosejs.com/index.html mongoose] may be of interest. (This is also covered in the Learning Node book.)

Latest revision as of 20:34, 1 March 2013

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. If you find this boring, skip to the next part.

Node and MongoDB

Recall that we covered a Node app that used MongoDB in the simple blog tutorial.

You have now learned enough background that this tutorial on making a simple blog that we previously covered should make a lot more sense. Note that this tutorial is based on an older version of Node; a slightly revised version of the code (more in keeping with how we've been using express in class) is available here. (Don't forget to run npm install after unpacking!)

This version of the code follows the tutorial up until around where comments are added. Start reading the tutorial from the beginning and follow along in the code in blog-updated. Finish the blog example by adding the necessary code, style sheets, and templates to implement a simple commenting system. (Some of this code is already present.)

If doing that is too easy, add tags to the posts! That will require you to both change the appearance of the application and change what is stored in MongoDB.

Learning more

To learn more about MongoDB, try out other tutorials.

See Chapter 10 of Learning Node for an introduction to Node and MongoDB.

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. (This is also covered in the Learning Node book.)