March 2012
Beginner to intermediate
138 pages
3h 21m
English
In Chapter 3, we presented Burt’s Books as an example of how to build a sophisticated web application with Tornado’s template tools. In this section, we’ll show you a version of the Burt’s Books example that uses MongoDB as a data store. (You’ll want to review the Burt’s Books example from Chapter 3 before you continue.)
Let’s start with something simple: a version of Burt’s Books that reads its list of books from the database. The first thing we’ll need to do is create a database and a collection on our MongoDB server and populate it with book documents, like so:
>>>import pymongo>>>conn = pymongo.Connection()>>>db = conn["bookstore"]>>>db.books.insert({..."title":"Programming Collective Intelligence",..."subtitle": "Building Smart Web 2.0 Applications",..."image":"/static/images/collective_intelligence.gif",..."author": "Toby Segaran",..."date_added":1310248056,..."date_released": "August 2007",..."isbn":"978-0-596-52932-1",..."description":"<p>[...]</p>"...})ObjectId('4eb6f1a6136fc42171000000') >>>db.books.insert({..."title":"RESTful Web Services",..."subtitle": "Web services for the real world",..."image":"/static/images/restful_web_services.gif",..."author": "Leonard Richardson, Sam Ruby",..."date_added":1311148056,..."date_released": "May 2007",..."isbn":"978-0-596-52926-0",..."description":"<p>[...]</p>"...})ObjectId('4eb6f1cb136fc42171000001')
(We’ve omitted the descriptions of these ...
Read now
Unlock full access