Down & Dirty with MongoDB Part 1: the Plot

MongoDB is an open-source, document-based datastore that has been gaining traction with developers lately. Its popularity is most likely due to the “middle ground” it provides between relational databases like MySQL and key-value stores like Redis.

MongoDB

We’ve found the datastore a joy to use and wanted to feature it somehow on FYC. However, there are many, many introductory articles and getting started tutorials for MongoDB (also the information on the project’s website is spectacular), so we would be remiss to provide yet another basic intro.

Instead, we decided to highlight how the datastore is used from a few popular dynamic languages. 10gen – MongoDB’s creator – provides many official client drivers (libraries) and the open-source community has produced a handful of libraries as well. We couldn’t feature them all, so we chose three favorites – Ruby, Python, and PHP – to include in the series.

The Plot

Many demonstrations use throwaway “Hello World” type programs. We thought it would be much cooler to write something that we can actually use, build upon, and maybe derive some value from. With that in mind, we tried to think of an application that had the following characteristics:

  1. Real-world use case
  2. Few lines of code (~ 100)
  3. Simple to understand and implement
  4. No 3rd party libraries or frameworks
  5. Demonstrate the basic CRUD operations

For better or worse, we chose to write a command-line todo list app as it fit the requirements well.

The Spec

Our todo application is invoked from the command-line and works as follows:

  • todo – list all incomplete tasks sorted by priority then chronologically
  • todo next – list all incomplete tasks that are high priority
  • todo done – list all complete tasks chronologically
  • todo high “pay bills” – add high priority task called “pay bills”
  • todo low “get milk” – add low priority task called “get milk”
  • todo finish “pay bills” – complete task called “pay bills”
  • todo dont “get milk” – delete task called “get milk”
  • todo help – list all commands and their usage

todo-example

The only requirement outside of the user interface outlined above is that MongoDB be used to persist the todo list.

The Setup

An identical application will be written in Ruby, Python, and PHP using the official MongoDB drivers. Each language will get its own article in the series. You have the application requirements so feel free to code along in your language of choice. Also, we’d love to see versions in some other languages that we won’t be covering. Show us your skills by submitting them in the comments. We’ll happily tweet them out and link them up in our final article in the series!

Be sure to grab our RSS feed or follow @fuelyourcoding on Twitter so you don’t miss out as we get down & dirty with MongoDB!

Jerod Santo is an Editor at Fuel Your Coding and a contract software developer at RSDi where he works daily with Ruby, JavaScript, and related technologies. He loves shiny toys, powerful tools, and open-source software. Learn more about Jerod by visiting his homepage or following him on Twitter.

 

If you liked this article, please help spread the news on the following sites:

  • Bump It
  • Blend It
  • Bookmark on Delicious
  • Stumble It
  • Float This
  • Reddit This
  • Share on FriendFeed
  • Clip to Evernote