To Basic Step to NoSQL (with MongoDB)

This article is written to Introduce to a kind of new database type which means NoSql Databases. I hope this will help peoples who familier with SQL databases and not familier with NoSql databases.


What is NoSQL Database.
In simple, these kind of Databases are not use SQL (Structured Query Language) for database operations. In usual SQL databases, data is stored in table structure. To make db operations, we use SQL language

Ex:
        SELECT * FROM Users;

I'm not going to describe more about SQL Databases. You can refer this to learn about SQL
So NoSQL Databases use JSON documents, Tree structures, Graphs like things. Here I will use Mongo DB. You can make database operations in Mongo DB using methods.



Mongo DB
Mongo DB is a one of commonly used NoSQL database in now a days. It was initially released in 2009. It was written C++. It runs in multiple platforms. And it is compleately free.
MongoDB has items called collections which similer to tables in SQL Databases. We save our data items in those collections

Setup MongoDB
First you need to download and install mongo DB inorder to use it.
Download MongoDB: https://www.mongodb.com/download-center#community
then go to <mongoDB installation directory>/server/<version>/bin using Command Prompt.
then run mongod
      NOTE:
      You may need to create data/db in C drive 

Add Data to Database (Insert Operation)
Assume, we have this data
    username: michal
    lastname: knighter
    car: pontiac firebird
Want to save it in MongoDB.
This is the way we insert into MongoDB.

db.users.insert({"username":"michal", "lastname":"knighter", "car":"pontiac firebird"});

Here users is the name of collection. We insert our data to users collection.

Select Data from Database (Select Operation)
We can use find() method to get data from database.

db.users.find();
This is equal to ' Select * ' in SQL

You can find specific result by quering data like below
db.users.find({"username":"michal"});

So you will get all data with michal as username

Modify Data in Database (Update Operation)
Now, in our collection (users) we have these data
username: michal
lastname: knighter
car: pontiac firebird

Now, we want to change lastname: knighter -> knight and car : pontiac firebird -> KITT 2000.

In this case, we can use update method in mongo db

db.users.update({username:michal}, {$set:{lastname : knight, car : KITT 2000}});

Delete Data from Database (Delete Operation)
Now our collection looks like this

username: michal
lastname: knight
car: KITT 2000

Lets try to remove these data from users collection.

db.users.remove({username: michal});

Above are some basic steps to mongo db. You can refer Mongo DB Documentation  for more operations.

I think this will help you to make first step to NoSQL world !!

Thank You

Comments

Popular posts from this blog

CSRF Defence - Synchronizer Token Pattern Demo

Lets read emails in gmail using oAuth 2.0 (Application demo)

How to view queries executed in MySQL?