2. Data stored in 4 types
• Document
• Graph
• Key-value
• Wide-column
Overview - NoSQL Family
3. • An open source and Document Oriented Database.
• Data is stored in JSON like documents with no particular format.
• Developed by 10gen - Generic Public License & Commercial License.
• Designed with both Scalability and developer agility.
• High performance Database
• JSONiq – Query Language
What is MongoDB?
4. • Download and install suitable package for each
platform [Windows, Linux, Mac OSX, Solaris]
• Go to bin of installation folder: C:mongodb
• Type following command: mongodb – to run the server
• Run another command: mongo.exe
Installation
5. SQL Vs MongoDB
SQL Terms / Concepts MongoDB Terms / Concepts
database database
table collection
row document
column field
index index
Table joins (e.g. select queries) Embedded documents and linking
Primary keys _id field is always the primary key
Aggregation (e.g. group_by) Aggregation pipeline
6. Collections
• MongoDB stores documents in collections. Collections are analogous
to tables in relational databases.
• If a collection does not exist, MongoDB creates the collection
when you first store data for that collection.
13. Use-case: 1– Storing Log Data
Problem Statement:
Servers generate a large number of
events (i.e. logging,) that contain useful
information about their operation including
errors, warnings, and users behavior. By
default, most servers, store these data in
plain text log files on their local file
systems.
While plain-text logs are accessible
and human-readable, they are difficult to use,
reference, and analyze without holistic
systems for aggregating and storing these
data.
Solution:
Extract the relevant information from standard request logs data into individual fields
into a document. Relevant information might be host, timestamp, user agent and referrer.
Eventually your system’s events will exceed the capacity of a single event logging
database instance. In these situations you will want to use a sharded cluster, which takes
advantage of MongoDB’s sharding functionality.
14. Use-case: 2 – TV Shows
Solution:
The set of information about a particular TV show is one big nested key/value data
structure. Inside a TV show, there’s an array of seasons, each of which is also a hash. Within
each season, an array of episodes, each of which is a hash, and so on. This is how MongoDB models
the data. Each TV show is a document that contains all the information we need for one show. All
of the data we need for a TV show is under one document, so it’s very fast to retrieve all this
information at once, even if the document is very large.
Problem Statement:
Each show has many seasons, each season has
many episodes, and each episode has many reviews and
many cast members. When users come into this site,
typically they go directly to the page for a
particular TV show. On that page they see all the
seasons and all the episodes and all the reviews and
all the cast members from that show, all on one page.