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

This site uses Akismet to reduce spam. Learn how your comment data is processed.