Tornado – MongoDB

Yes, Tornado gells well with many databases like mysql, sqlite and mongodb. Below is an example of database connectivity and interaction with MongoDB from Tornado.

In this example, the user or client connects MongoDB database : library and collection: articles )with HTTP requests.

  • get() – displays the records of mongodb collection with article id
  • post() – helps the client to add articles with id, article title, and genre
  • delete() – deletes the articles’s information

Please note: the example assumes that mongo server and pymongo (python driver for mongodb) is installed on the system

Client Request

The client program:

  • Adds two records to the articles collection with HTTP POST request
  • It then reads one of the articles with the HTTP GET request with article 1
  • Client then drops all the records of the collection with HTTP DELETE request


{u'genre': u'comedy', u'_id': ObjectId('503f4a601d41c81bf9d3360d'), u'id': u'1', u'author': u'B'}
No Articles found

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s