Thank you SQL! Hello NoSQL, the future of consumer web database application

For every software developer, SQL is their best friend when updating, deleting, adding and creating data into database. Below statement should be very familiar:

select * from users;

Now, how about this one?


When developing interactive web application, ajax is the norm of methodology used and the data interchange most probably JSON type.

Converting JSON data into SQL insert/update statement is boringly necessity of daily tasks. What if you can just simply save it in JSON format and get it as the same JSON?

Say hello to one of the NoSQL database type: MongoDB.

MongoDB is new kind of database which data are stored in form of JSON documents. Yes, that is right.. JSON format!

And the best part, not to worry so much about tables, schema, columns, etc! You just simply save it and retrieved it just like that.

MongoDB have many drivers for PHP, Java, C, C++ and others popular programming language out there. Heck, you can use REST protocol to save and update your data with this tool via JQuery or whatsoever JavaScript framework.

Ok, enough talk.. let see how it work.

C:mongodbbin>mongod --dbpath=c:mongodbdata
MongoDB shell version: 2.0.0
connecting to: test 

Now, we can interact with Mongo console.

> db.users.insert({"username":"junaidix"})
> db.users.insert({"username":"carneyz"})
> db.users.find()
{ "_id" : ObjectId("4e9fa94a122e9bd1bfc22743"), "username" : "junaidix" }
{ "_id" : ObjectId("4e9fa972122e9bd1bfc22744"), "username" : "carneyz" }

Here what’s happened in equivalent SQL:
1) insert into users value(“junaidix”)
2) insert into users value(“carneyz”)
3) select * from users

Yes, no need to create table users since it will automatically created. But in MongoDB, it called Collections. Logical to says it’s “collections of users documents”.

Now, take a look of this:

> db.users.insert({"username":"khayla","gender":"female"})
> db.users.find()
{ "_id" : ObjectId("4e9fa94a122e9bd1bfc22743"), "username" : "junaidix" }
{ "_id" : ObjectId("4e9fa972122e9bd1bfc22744"), "username" : "carneyz" }
{ "_id" : ObjectId("4e9fab8d122e9bd1bfc22745"), "username" : "khayla", "gender": "female" }

I’ve added another data with different structure, and it work perfectly without need to add new columns whatsoever to the database! Because it’s really a documents. You can append any valid JSON data to it.

With this MongoDB, it will shape the new paradigm of my web development technique since I do not have to worry about the changes of data structure because it naturally supported by MongoDB.

Ok, that’s it for now. You folks can try it yourself and read a nice written documentation and manuals here:

Leave a Reply