MongoDB – making life simpler!

When I heard about MongoDB from a friend, I had no clue what it had in store for me. For a programmer like me, who works with jQuery a LOT, MongoDB fit right into one part of my jigsaw puzzle 🙂 Let me decode the Greek and Latin I just spoke.

jQuery is a UI development language that is built using Javascript libraries.It is an easy way to develop UI such that there is least difference in cross browser functionality. If Javascript were breadcrumbs, jQuery is crumbs rolled into balls.

Objects in Javascript are represented using JSON. JSON stands for Javascript Object Notation. They are lightweight, easy to decode. The look like this in their easiest form:

{ “name”:”Pearl”,

“age:24}

Say one day you wake up and decide to build a webapp that captures data about people and stores it in a database. And you need to do it fast. MongoDB would be the perfect choice. You create your UI using html and jquery, you can use enhanced engines like Node.js along with jQuery, or jsp and servlets(would add some overhead) to write your logic that lies between your database and UI, and mongoDB to store the data just the way it gets passed down from the UI in JSON format! Isnt that cool? A quick easy solution.

MongoDB is also easily scalable too.it is less restrictive than relational database. If RDBMS is ur strict teacher , MongoDB is ur fun aunt. Of course they are not replaceable, but for a large set of purposes mongoDB would serve just fine.

For starters – MongoDB has no joins, no transactions persay, and no sql! The data is stored in ‘collections’ which are composed of ‘documents’ which are nothing but – JSON objects as above! So what we SQLers knew as a table, is now a collection. What we knew as rows, is now a document. Of course, each item in the row constitutes separate  columns.

So a collection ‘friends’ may look like this:

{“_id”:”xxxxxxxxxxxxxxxx”,”name”:”DS”, “category”:”best”,”profession”:”Data warehousing”}

{“_id”:”yyyyyyyyyyy”,”name”:”SM”, “category”:”best”,”””profession”:”Telecom”,”hobbies”:[“acting”,”reading”]}

{“_id”:”zzzzzzzzz”,”name”:”AS”, “category”:”best”,”profession”:”Application development”, “interests”:[“music”]}

MongoDB has no schema. The number of fields in each document may vary, even while being part of same collection. The _id field that you see is special – it is present in every document and is unique, added automatically. It can be manipulated, but carefully.

MongoDB has a lot to offer – it has indexing capabilities, great provisions for querying, sharding ( that allows for high levels of scalability), utilities like GridFS that allow you to store files of any size in MongoDB .. and many more that I would love to write about in the coming posts.

P.S. 10gen are the creators of MongoDB and have many amazing online free trainings related to MongoDB that you can take advantage of if you’d like.

Leave a comment