0% found this document useful (0 votes)
16 views

Module - 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Module - 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1)​ What is a Document database? Explain with an example.

Explain its features


briefly.

A)​ A document database is a type of NoSQL database designed to store, retrieve, and
manage document-oriented information, which is typically represented as JSON-like
documents. Unlike traditional relational databases (RDBMS), document databases allow
each "document" (similar to a row in an RDBMS) to have a unique structure. This
flexibility makes document databases well-suited for applications requiring a schema that
can adapt over time

Example:

{
"firstname": "Martin",
"likes": [ "Biking", "Photography" ],
"lastcity": "Boston",
"lastVisited":
}

The above document can be considered a row in a traditional RDBMS. Let’s look at
another document:
1.​ Looking at the documents, we can see that they are similar, but have
differences in attribute names.
2.​ This is allowed in document databases. The schema of the data can differ
across documents, but these documents can still belong to the same
collection—unlike an RDBMS where every row in a table has to follow the
same schema.

There are 5 features of Document Databases:


1. Consistency
2. Transactions
3. Availability
4. Query features
5. Scaling
1)​ Consistency
●​ Consistency in MongoDB is managed using replica sets, where data
is copied to multiple nodes
●​ Trade-off: Stronger consistency (more nodes) slows down write
performance.
2)​ Transactions
●​ Single-document transactions (atomic operations) are supported.
●​ Multi-document transactions (like in SQL databases) aren’t typical in
MongoDB, although some NoSQL systems support them.
3)​ Availability
Availability in MongoDB is ensured through replica sets. A master node
handles writes, while slave nodes replicate data.
●​ If the master fails, a new master is automatically elected.
4)​ Query Features
●​ MongoDB has a JSON-based query language similar to SQL
●​ Example of Sql: SELECT * FROM order WHERE customerId = "1234";
●​ Example of MangoDb Eqivalent : db.order.find({ customerId: "1234"
});
5)​ Scalaing:
●​ MongoDB supports horizontal scaling for both reads and writes

2) Briefly explain scaling feature in document databases, with a neat diagram.


A)
●​ Read Scaling: Adding more secondary nodes in a replica set allows load
distribution across these nodes, especially for read-heavy applications.
Write
●​ Scaling: MongoDB uses sharding, a form of data partitioning that distributes
data across multiple nodes based on a shard key. This enables applications
to handle higher write loads by balancing data among shards and
dynamically redistributing data as nodes are added.

3)Explain Sutiable Use Cases of Document Database


A)
1.​ Event Logging:
❖​Applications have different event logging needs; within the
enterprise, there are many different applications that want to log
events.
❖​Document databases can store all these different types of events and
can act as a central data store for event storage.
❖​This is especially true when the type of data being captured by the
events keeps changing.
❖​Events can be sharded by the name of the application where the
event originated or by the type of event such as order_processed or
customer_logged.

2.​ Content Management Systems, Blogging Platforms :


❖​MongoDB’s schema-less nature is perfect for storing content like:
i.​ User comments
ii.​ User profiles
iii.​ Web-facing documents
❖​Since it uses JSON documents, it easily manages diverse and changing
data structures.

3.​ Web Analytics or Real-Time Analytics :


❖​ Document databases can store data for real-time analytics; since
parts of the document can be updated, it’s very easy to store page
views or unique visitors, and new metrics can be easily added
without schema changes.
4.​ E-Commerce Applications:
●​ E-commerce applications often need to have flexible schema for
products and orders, as well as the ability to evolve their data models
without expensive database refactoring or data migration (“Schema
Changes in a NoSQL Data Store.

4) When document databases are not suitable (When Not to Use) ? Explain.

A)​ 1. Complex Transactions Spanning Different Operations


●​ What it means: If your application requires transactions that need to work
across multiple documents (like updating several documents in a single,
atomic operation), a document database might not handle it efficiently.
○​ Why it's a problem: Most document databases do not support
multi-document atomic transactions by default.
○​ Alternative: Some document databases, like RavenDB, support these
kinds of operations. However, if your use case heavily relies on
complex transactional requirements, a relational database may be a
better fit.

2. Queries against Varying Aggregate Structure :

❖​Flexible schema means that the database does not enforce any restrictions
on the schema.
❖​Data is saved in the form of application entities. If you need to query these
entities ad hoc, your queries will be changing (in RDBMS terms, this would
mean that as you join criteria between tables, the tables to join keep
changing).
❖​ Since the data is saved as an aggregate, if the design of the aggregate is
constantly changing, you need to save the aggregates at the lowest level of
granularity—basically, you need to normalize the data. In this scenario,
document databases may not work.

You might also like