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.
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.
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:
- Real-world use case
- Few lines of code (~ 100)
- Simple to understand and implement
- No 3rd party libraries or frameworks
- 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.
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
The only requirement outside of the user interface outlined above is that MongoDB be used to persist the todo list.
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!