If you have experience with relational databases like mysql, oracle then this tutorial will give you mapping of concepts between relational databases and mongodb.
Also help you to get a smooth transition from relational database world to the nosql world.
The following keywords from the both the world are mapped in the following table.
|Relational Database||MongoDB / NoSQL|
Table and Collection: A business entity in the world of business maps to the table , where each attribute maps to the column of a table and the values are kept in the rows, similarly an entity is maps to the collection in the mongo world , the attributes maps to the key of the entity and values are corresponds to the value section of the key value pair. Lets see an example.
Employee is an business entity which needs to be persisted. The attributes of the Employee are "name", "age", "sex". To make them into the table in the relational database you will have to define the structure first and then insert rows into them.
Step 1: Create the table structure
create table EmployeeTable(name varchar(20),age int(2),sex char(6));
Step 2: Once the table is created you can insert data into them.
insert into EmployeeTable (name,age,sex) values ( "Mike",12,"male");
And repeat the step 2 for as many employees in the organization
Now lets talk about the ways to deal the same business entity in MongoDB.
Step 1: A collection in the MongoDB don't have a structure to define , but just the name of the entity just like EmployeeTable
The statement above will create a collection ( if not exists already ) and save the document (we are going to study next) into the collections.
|Need to define the structure first||There is no structure involved|
|Each business attribute is a column||Each business attibute a key|
|Each entry in the table is called a row/tuple or some refer it as a record||Each entry in the collection is called a document|
|The schema change is expensive,if you decides to add one extra attribute you will have to modify the table schema first by alter command||The schema is dynamic, you just need to save another document with modified / new attribute / key value pair|