Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

1.

Key Value Stores

• A key value store uses a hash table in which there exists a unique key and

a pointer to a particular item of data.

• Imagine key value stores to be like a phone directory where the names of the

individual and their numbers are mapped together.

• Key value stores have no default query language. You retrieve data using get,

put, and delete commands. This is the reason it has high performance.

• Applications: Useful for storage of Comments and Session information.


2. Wide column stores
• A wide-column database (also known as a column-family database) is a type of
NoSQL database that stores data in a column-family format. A column family is
a collection of rows and columns, where each row has a unique key and each
column has a name, value, and timestamp.
• Each column family is a container of rows in an RDBMS table.
The key identifies the row consisting of multiple columns.
• Rows do not need to have the same number of columns. Columns can be added
to any row at any time without having to add it to other rows. It is a partitioned
row store.
How does a columnar database store data?
3. Document Databases

• ‌Document stores uses JSON, XML, or BSON (binary encoding of JSON)

documents to store data.

• It is like a key-value database, but a document store consists of semi-structured

data.

• A single document is to store records and its data.

• ‌It does not support relations or joins.


4. Graph databases

 ‌Nodes and relationships are the essential constituents of graph databases. A node represents

an entity. A relationship represents how two nodes are associated.

 ‌In RDBMS, adding another relation results in a lot of schema changes.

 Graph database requires only storing data once (nodes). The different types of relationships

(edges) are specified to the stored data.

 The relationships between the nodes are predetermined, that is, it is not determined at query

time.

 Traversing persisted relationships are faster.


 It is difficult to change a relation between two nodes. It would result in regressive changes in the database.

 Example: This image is how MySQL works where it has to perform many operations to find a correct result for Alice.
A graph database, which predetermines relationships.
 Aggregation is a way of processing a large number of documents in a collection
by means of passing them through different stages.
 The stages make up what is known as a pipeline.
 The stages in a pipeline can filter, sort, group, reshape, and modify documents
that pass through the pipeline.
•$match stage – filters those documents we need to work with, those that fit our needs

•$group stage – does the aggregation job

•$sort stage – sorts the resulting documents the way we require (ascending or
descending)
db.collectionName.aggregate(pipeline, options)

•where collectionName – is the name of a collection,


•pipeline – is an array that contains the aggregation stages,
•options – optional parameters for the aggregation
This is an example of the aggregation pipeline syntax:
pipeline = [ { $match : { … } }, { $group : { … } }, { $sort : { … } } ]
Aggregation Operations
Aggregation operations process multiple documents and return computed results. You can use
aggregation operations to:
•Group values from multiple documents together.
•Perform operations on the grouped data to return a single result.
•Analyze data changes over time.
To perform aggregation operations, you can use:
•Aggregation pipelines, which are the preferred method for performing aggregations.
documents, group documents, and calculate values.
•The documents that are output from a stage are passed to the next stage.
•An aggregation pipeline can return results for groups of documents. For example,
return the total, average, maximum, and minimum values.

: :
{ field { $mod [ divisor, remainder ] } }
db.std.aggregate([ { $match: { "continent": "North America" } }] )

db.std.aggregate([ { $sort: { "population": -1 } }] )

db.std.aggregate([ { $match: { "continent": "North America" } }, { $sort: { "population": 1 } }] )

db.std.aggregate([ { $group: { "_id": "$continent" } }] )


specify multiple single-field values in a grouping expression. The following example method will group documents
based on the values in the continent and country documents:

db.std.aggregate([ { $group: { "_id": { "continent": "$continent", "country": "$country" } } }] )

db.std.aggregate([ { $group: { "_id": { "continent": "$continent", "country":


"$country" }, "highest_population": { $max: "$population" }, "first_city":
{ $first :"$name"},"cities_in_top_20": { $sum: 1 } } } ])
db.col1.aggregate([ { $group:{ _id:'$department.name', totalEmployees: { $sum:1 }}}])

db.col1.aggregate([ { $match: { gender: "male" } }, { $group: { _id: '$department.name', totalEmployees: { $sum: 1 } } }])

You might also like