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

2383_1019_DOC_NoSQL Databases

Uploaded by

Narayana swamy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

2383_1019_DOC_NoSQL Databases

Uploaded by

Narayana swamy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NoSQL Databases: A Beginner's Guide - Student

Handout
1. Introduction to NoSQL Concepts
What is a NoSQL Database?
Definition: NoSQL stands for "Not Only SQL." These databases are designed to handle
large volumes of data, high user loads, and scalability, unlike traditional relational
databases.

Characteristics of NoSQL Databases


1. Schema Flexibility:
Store data without a predefined schema.
Example: Storing user profiles with varying fields.
Example: Product catalogs with different attributes.
Example: Blog posts with diverse metadata.
2. Distributed Nature:
Data is spread across multiple servers.
Example: Data replication across data centers.
Example: Load balancing across servers.
Example: Fault tolerance through data distribution.
3. High Scalability:
Easily grow as data grows.
Example: Adding servers to handle increased traffic.
Example: Scaling out for seasonal demand spikes.
Example: Supporting millions of concurrent users.
4. Horizontal Scaling:
Scale by adding more servers.
Example: Expanding server clusters.
Example: Distributing data processing tasks.
Example: Increasing storage capacity by adding nodes.
2. Types of NoSQL Databases
a. Document Databases (e.g., MongoDB)
Structure: Data stored in documents (JSON/BSON) grouped into collections.
Use Case: Complex, hierarchical data storage.
Example: User profiles with nested information.
Example: Product catalogs with varied specifications.
Example: Content management systems for blogs.

b. Key-Value Databases (e.g., Redis)


Structure: Data stored as key-value pairs.
Use Case: Caching, session management, real-time data.
Example: Storing user session data.
Example: Caching frequently accessed data.
Example: Real-time analytics for web applications.

c. Columnar Databases (e.g., Cassandra)


Structure: Data stored in columns.
Use Case: Large datasets across many servers.
Example: Time-series data for IoT devices.
Example: Log data analysis for monitoring systems.
Example: Data warehousing for business intelligence.

d. Graph Databases (e.g., Neo4j)


Structure: Data stored in nodes and edges.
Use Case: Modeling complex relationships.
Example: Social network connections.
Example: Recommendation engines for e-commerce.
Example: Fraud detection in financial systems.

3. Document Databases (MongoDB)


Collections and Documents
Collection: Group of documents.
Document: JSON-like object storing data.

Basic CRUD Operations in MongoDB


1. Create: Insert a new document.

db.users.insertOne({ name: "Rahul", age: 25 });

Example: Adding a new user profile.


Example: Inserting a new product entry.
Example: Creating a new blog post.
2. Read: Query the database.

db.users.find({ name: "Rahul" });

Example: Retrieving user information.


Example: Fetching product details.
Example: Displaying blog content.
3. Update: Modify an existing document.

db.users.updateOne({ name: "Rahul" }, { $set: { age: 26 } });

Example: Updating user age.


Example: Modifying product price.
Example: Editing blog post content.
4. Delete: Remove a document.

db.users.deleteOne({ name: "Rahul" });

Example: Deleting a user account.


Example: Removing a discontinued product.
Example: Erasing an outdated blog post.
Querying with MongoDB Query Language (MQL)
Perform complex queries.

db.users.find({ age: { $gt: 25 } });

Example: Finding users older than 25.


Example: Searching for products above a price threshold.
Example: Filtering blog posts by publication date.

4. Advantages of NoSQL for Big Data Applications


a. Horizontal Scalability
Scale by adding more servers.
Example: Expanding infrastructure for data growth.
Example: Handling increased user traffic.
Example: Supporting large-scale data processing.

b. Distributed Data Storage


Store data across multiple servers.
Example: Ensuring data availability across regions.
Example: Balancing load across server clusters.
Example: Achieving fault tolerance through redundancy.

c. High Availability
Continue functioning despite server failures.
Example: Maintaining uptime during server outages.
Example: Providing uninterrupted service to users.
Example: Ensuring data accessibility 24/7.

5. Activity: Create a MongoDB Collection and Perform


Basic Queries
1. Create a MongoDB Collection:

db.createCollection("students");

Example: Setting up a collection for student records.


2. Insert a Document:

db.students.insertOne({ name: "Amit", age: 22, course: "Computer


Science" });

Example: Adding a new student entry.


3. Query the Collection:

db.students.find({ age: { $gt: 20 } });

Example: Retrieving students older than 20.


4. Update a Document:

db.students.updateOne({ name: "Amit" }, { $set: { age: 23 } });

Example: Updating a student's age.


5. Delete a Document:

db.students.deleteOne({ name: "Amit" });

Example: Removing a student record.

Conclusion
NoSQL databases offer a flexible, scalable, and highly available solution for modern
applications. They are particularly suited for Big Data applications due to their ability to handle
large volumes of data and high traffic efficiently.

Key Takeaways:
NoSQL databases are schema-less, distributed, and highly scalable.
Four main types: Document, Key-Value, Columnar, and Graph.
MongoDB is a popular document-based NoSQL database.
Ideal for Big Data applications due to horizontal scalability and distributed nature.

Feel free to explore further and practice with MongoDB to solidify your understanding!

You might also like