Beginner'S Guide To Concepts of Nosql and Mongodb: Documented By: - Maulin Shah
Beginner'S Guide To Concepts of Nosql and Mongodb: Documented By: - Maulin Shah
Purpose
Purpose of writing this document is to guide beginners to NoSQL concepts and MongoDB database.
Introduction
In recent years as internet and new technologies has become more accessible to people amount of data
that was being generated in 1990s in one year is now in 2016 being generated in one hour and maybe
less time than that. And this rate is increasing rapidly every day. But, traditional methods and
technologies of collecting and processing data (Like SQL, and different frameworks) were not designed
to handle this huge amount of data. So, new methods and technologies has become necessity of time.
Because of that we are getting to see new technologies like Hadoop, NoSQL, etc. which are specially
designed to handle these amount of data.
Shortcomings of RDBMS
1) Inability to handle unstructured/semi-structured data. Because as internet has expanded year over
year more unstructured/semi-structured data is being produced and RDBMS cannot handle that.
2) CRUD operations are not fast enough to give results and are costly operations as it has to deal with
joins and maintaining relationship among different data.
3) Because of Schema structure it is hard to scale out RDBMS.
To overcome these shortcomings NoSQL databases were introduced
CAP Theorem
It states that any distributed system; we should have three aspects C (consistency), A (Availability), P
(Partition tolerance). But unfortunately we can have any two at same time in a distributed system.
Consistency every user should be able to see same data after execution of an operation.
Availability Less or no downtime.
Partition Tolerance system should work properly even though communication among server is not
reliable.
MongoDB
Learning MongoDB is quite easy and fun. MongoDB is Document-Oriented database; it is open source
NoSQL database. We can use it as alternative of RDBMS. It can give high performance by using with
more specialized NoSQL databases.
DATABASE
COLLECTIONS
DOCUMENTS
FIELDS
1) MongoDB has same concept like schema in Oracle SQL; within a MongoDB instance (like SQL
schema) you can have zero or more database, each acting as high level container for everything else.
2) Collection in MongoDB is same as tables in RDBMS. MongoDB can have zero or more collection in it.
3) Document is MongoDB can be seen as row in RDBMS. Collections are made of zero or more
documents.
4) Fields in MongoDB can be seen as Column in RDBMS. Document can have zero or more fields in it.
5) Indexes concept is same as in SQL.
6) Cursor in MongoDB is new concept which is used when we ask MongoDB for data it returns a pointer
to a result set which is called cursor.
Find()
It works like select statement in SQL.
Example
db.example.find() -> select * from example;
db.example.find({Age:24}) -> select * from users where Age=24;
comparison operators
List of operators
$ne -> not equal to, $gt -> greater than, $gte -> greater than equal to, $lt -> less than, $lte -> less than
equal to , $in, $nin -> not in, $mod, $exists
example
db.example.find({Name:{$ne:Maulin}})
above query will return all documents from user collection where name is Not Maulin.
Logical operators
List of operators
$And, $or
Example
Db.example.find({Name:Maulin,Age:24}) -> It will return all documents where Name is Maulin AND
Age is 24.
Easy!!! Right. So, this is it from my side. Learning new technology is not always hard.
** ALL THE BEST **
** HAPPY LEARNING **