Share on Google Plus
Now a Days, we are hearing a lot about MongoDB.
So, in this post I will try to briefly introduce to MongoDB.
MonGoDB is "Non-Relational, JSON, Document Store".
Explaining in detail,
Non-Relational, --> The DB we use most like SQl, Oracle are Relational DBs(RDBMS). They do have the fixed schemas, lots of tables. So Non-relational in nothing like that.
JSON : (JavaScript Object Notation) : It is basically a document with information in the form of key value pair.
for example,
{
name:"lorem",
address:"ipsum
}
thats it.
A simple JSON document where name and address are key
and "lorem" and "ipsum" are corresponding values.
So, MongoDB is the Non Relational database which stores information using DOCUMENT and that document is a JSON document.
MongoDB stores collections of documents.
(Consider the above exxample as collection "Person" with a document)(will elaborate it later more)
Need of MongoDB:
The Databases we use now a days, mostly SQL, Oracle(RDBMS) provides lots of functionaily but they lack one thing, which is Performance and Scalibility.So, MongoDB aims at providing the same level of functionality but providing high performance and scalibility.
One more advantage of MongoDB is that it supports Dynamic Schema.
Meaning is RDBMS(SQL,Oracle etc), tables have fixed Schema like a table can have fixed colums and these columns cant be changed at run-time.
But in MongoDB, columns can be changed.
i.e
Suppose a collection "Person", can have two documents,
1st Document
{
name:"lorem",
address:"ipsum"
}
2nd Doc.
{
name:"hello",
DOB:"13-Aug"
}
So, these two docs have "name" has in common but 1st document has "address" while 2nd doesnt have this. Same with "DOB".
This is perfectly valid in MongoDB but not possible in SQL,
Also, there is one more thing,
Consiser a document,
{
name:"lorem",
DOB: "13-Aug",
fav_color : ['red','blue']
}
Yeah, dont get confused,.
This document contains a list name, fav_color and DOB.
only difference is fav_color is storing an array of value instead of a single value.
This is possible in SQl, but you cant store all this information in one table. There needs a different table for fav_Color..
But there are also some limitations of MongoDB,
a) It doesn't support Joins
b) doesnt support Transactions
To install it,
Use the link : http://www.mongodb.org/downloads
Download the version.
Then extract the content to a directory (say C:\MongoDB)
Now before frirng any command it needs "/data/db" directory in current directory.
So create the dircrctory as
md C:\data
md C:\data\db
now navigate to C:\MongoDB and run mongod.exe in a command prompt.
now to create a db, open another command prompt and type "mongo.exe" and press Enter,
This should take you to MongoDB console,
Now create DB using
use test // test is DB name
to add data to collection
db.persons.save({name:"lorem",address:"ipsum"})
where
db -> keywod
persons-> collection name
save -> function
to view the save doc
db.persons.find()
.
Thats it..
Hope this will help...
You can also check our Microservices post
Introduction to Microservices
So, in this post I will try to briefly introduce to MongoDB.
MonGoDB is "Non-Relational, JSON, Document Store".
Explaining in detail,
Non-Relational, --> The DB we use most like SQl, Oracle are Relational DBs(RDBMS). They do have the fixed schemas, lots of tables. So Non-relational in nothing like that.
JSON : (JavaScript Object Notation) : It is basically a document with information in the form of key value pair.
for example,
{
name:"lorem",
address:"ipsum
}
thats it.
A simple JSON document where name and address are key
and "lorem" and "ipsum" are corresponding values.
So, MongoDB is the Non Relational database which stores information using DOCUMENT and that document is a JSON document.
MongoDB stores collections of documents.
(Consider the above exxample as collection "Person" with a document)(will elaborate it later more)
Need of MongoDB:
The Databases we use now a days, mostly SQL, Oracle(RDBMS) provides lots of functionaily but they lack one thing, which is Performance and Scalibility.So, MongoDB aims at providing the same level of functionality but providing high performance and scalibility.
One more advantage of MongoDB is that it supports Dynamic Schema.
Meaning is RDBMS(SQL,Oracle etc), tables have fixed Schema like a table can have fixed colums and these columns cant be changed at run-time.
But in MongoDB, columns can be changed.
i.e
Suppose a collection "Person", can have two documents,
1st Document
{
name:"lorem",
address:"ipsum"
}
2nd Doc.
{
name:"hello",
DOB:"13-Aug"
}
So, these two docs have "name" has in common but 1st document has "address" while 2nd doesnt have this. Same with "DOB".
This is perfectly valid in MongoDB but not possible in SQL,
Also, there is one more thing,
Consiser a document,
{
name:"lorem",
DOB: "13-Aug",
fav_color : ['red','blue']
}
Yeah, dont get confused,.
This document contains a list name, fav_color and DOB.
only difference is fav_color is storing an array of value instead of a single value.
This is possible in SQl, but you cant store all this information in one table. There needs a different table for fav_Color..
But there are also some limitations of MongoDB,
a) It doesn't support Joins
b) doesnt support Transactions
To install it,
Use the link : http://www.mongodb.org/downloads
Download the version.
Then extract the content to a directory (say C:\MongoDB)
Now before frirng any command it needs "/data/db" directory in current directory.
So create the dircrctory as
md C:\data
md C:\data\db
now navigate to C:\MongoDB and run mongod.exe in a command prompt.
now to create a db, open another command prompt and type "mongo.exe" and press Enter,
This should take you to MongoDB console,
Now create DB using
use test // test is DB name
to add data to collection
db.persons.save({name:"lorem",address:"ipsum"})
where
db -> keywod
persons-> collection name
save -> function
to view the save doc
db.persons.find()
.
Thats it..
Hope this will help...
You can also check our Microservices post
Introduction to Microservices
Comments
Post a Comment