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

NO SQL

The document provides an introduction to NoSQL databases, detailing their types including Document-Oriented, Key-Value Stores, Column-Family Stores, and Graph Databases, along with their characteristics and use cases. It also covers practical exercises related to MongoDB and Cassandra, including installation, CRUD operations, and data modeling. Additionally, it introduces Neo4j Graph Databases, highlighting key concepts, benefits, use cases, and basic CRUD operations.

Uploaded by

abhihome1109
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)
2 views

NO SQL

The document provides an introduction to NoSQL databases, detailing their types including Document-Oriented, Key-Value Stores, Column-Family Stores, and Graph Databases, along with their characteristics and use cases. It also covers practical exercises related to MongoDB and Cassandra, including installation, CRUD operations, and data modeling. Additionally, it introduces Neo4j Graph Databases, highlighting key concepts, benefits, use cases, and basic CRUD operations.

Uploaded by

abhihome1109
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/ 13

Practical-1

Aim:- Introduction and Types of NoSQL Databases.

Introduction:

In today's data-driven world, the need for efficient and scalable data storage solutions
has led to the rise of NoSQL (Not Only SQL) databases. Unlike traditional relational
databases, NoSQL databases offer a flexible and schema-less approach to data
management, making them well-suited for handling large volumes of unstructured or
semi-structured data. This practical manual aims to explore the different types of
NoSQL databases, their characteristics, use cases, and best practices for
implementation.

Types of NoSQL Databases:

Document-Oriented Databases: Document-oriented databases store data in flexible,


self-describing documents, usually in formats like JSON (JavaScript Object Notation) or
BSON (Binary JSON). Each document can have its own unique structure, allowing for
easy storage and retrieval of complex data structures. Document- oriented databases
excel in scenarios where data schemas may evolve over time or when dealing with
variable data types. Popular examples of document-oriented databases include
MongoDB, Couchbase, and Apache CouchDB.

Key-Value Stores: Key-value stores are among the simplest types of NoSQL
databases, where data is stored as a collection of key-value pairs. These databases
offer fast and efficient retrieval of data based on unique keys but typically lack
complex querying capabilities. Key-value stores are commonly used for caching,
session management, and real-time analytics. Examples of key-value stores include
Redis, DynamoDB (Amazon Web Services), and Riak.
Column-FamilyStores:Column-family stores organizedata into columns ratherthan rows,
makingthem suitablefor handlinglarge-scale,distributeddata sets. These databases are
optimized for read-heavy workloads and excel in scenarios requiringefficient storageand
retrievalof largevolumes of data with varying attributes.
Column-family stores are commonly used in data warehousing, analytics,and time-
series data storage.Notable examples of column-family databases include Apache
Cassandra, HBase (Hadoop Database), and ScyllaDB.

Graph Databases:Graph databases are designed to representand query relationships


between data entities,makingthem ideal for applicationsinvolvingcomplex
interconnectionsand networks. In graph databases, data is stored as nodes (entities),
edges (relationships),and properties(attributes). This structureenables powerful querying
capabilitiesfor traversingrelationshipsand analyzingconnected data. Graph databases
are commonly used in social networks, recommendationengines,fraud detection, and
network analysis.Examples of graph databases include Neo4j, ArangoDB,and Amazon
Neptune (a fullymanaged graph database service from AWS).
Practical-2

Aim:- Introduction and Installation of MongoDB.


Practical-3

Aim:- Basic CRUD Operations with MongoDB.

Basic CRUD Operations with MongoDB:

MongoDB supports CRUD operations, which stands for Create, Read, Update, and Delete. These operations
are fundamental for interacting with data in MongoDB. Below, I'll provide examples of each CRUD
operation using MongoDB's shell.

Create (Insert) Operation:


To create a new document in MongoDB, you can use the insertOne() or insertMany() methods.

Insert a single document:

db.users.insertOne({ name: "John Doe", email: "[email protected]" }); OUTPUT:-

Read (Query) Operation:


MongoDB provides powerful querying capabilities using the find() method.

db.users.find();

OUTPUT:-

OUTPUT:-
Practical-4

Aim:- Introduction and Setup of Cassandra.

Download Cassandra:
Start by visiting the official Apache Cassandra website at https://cassandra.apache.org/ and
navigate to the Downloads section. Choose the appropriate version of Cassandra based on your
operating system (Windows, macOS, or Linux) and download the installer package or tarball.

Install Cassandra on Windows:


Once the installer package is downloaded, double-click it to start the installation process.
Follow the on-screen instructions in the setup wizard. You can choose the installation
directory and other configuration options.
After installation, navigate to the Cassandra installation directory (usually located at
C:\Program Files\Apache Cassandra) and run the cassandra.bat file to start the Cassandra
server.

Verify Cassandra Installation:


Open a web browser and go to http://localhost:9042/. You should see the Cassandra Query
Language (CQL) shell interface if Cassandra is running successfully.
Alternatively, you can use the nodetool status command in the terminal to check the status of
the Cassandra cluster and nodes.

Access Cassandra CQL Shell (cqlsh):


To interact with Cassandra, you can use the CQL shell (cqlsh), which provides a command- line
interface for executing CQL queries.
Open a terminal or command prompt and navigate to the Cassandra installation directory.
Run the following command to start the CQL shell:
bash
bin/cqlsh
You can now use CQL commands to create keyspaces, tables, insert data, and perform
queries within the Cassandra database.
Practical-5

Aim:- Data Modeling and Simple Queries with Cassandra.

Understanding Data Replication:

Cassandra replicates data across multiple nodes in a cluster to ensure high availability and fault
tolerance.Replication strategies (e.g., SimpleStrategy, NetworkTopologyStrategy) define how data is
distributed across nodes and data centers.
Primary Key Design:
The primary key consists of a partition key (mandatory) and optional clustering columns.
The partition key determines data distribution across nodes, while clustering columns define data
sorting within a partition.
Denormalization and Query-Driven Design:
Denormalization is common in Cassandra to optimize read performance by reducing the need for
joins.Design tables based on specific query patterns to minimize data duplication and ensure efficient
queries.
Simple Queries with Cassandra:
Creating a Keyspace: Start by creating a keyspace, which acts as a container for tables in Cassandra.

CREATE KEYSPACE IF NOT EXISTS my_keyspace WITH


replication = {'class': 'SimpleStrategy', 'replication_factor': 1};

OUTPUT:-

Creating a Table:
Define a table with a suitable primary key based on your data model and query requirements
CREATE TABLE IF NOT EXISTS my_keyspace.users
( user_id UUID PRIMARY KEY, name TEXT, email
TEXT,
age INT
);

OUTPUT:-
Inserting Data: Insert data into the table using the INSERT INTO statement.
INSERT INTO my_keyspace.users (user_id, name, email, age)
VALUES (uuid(), 'John Doe', '[email protected]', 30);

OUTPUT:-
Practical-6

Aim:- Introduction to Neo4j Graph Databases.

Key Concepts in Neo4j:


1. Nodes: Nodes are the fundamental units in Neo4j and represent entities in your data model.
Each node can have properties that store data attributes.
2. Relationships: Relationships define connections between nodes and carry semantic meaning.
Relationships have types and can also have properties.
3. Properties: Properties are key-value pairs associated with nodes and relationships, storing
additional information about them.
4. Labels: Labels categorize nodes into groups, providing a way to organize and query related
nodes efficiently.

Benefits of Neo4j Graph Databases:


1. Flexible Data Modeling: Neo4j's graph model allows for flexible and expressive data modeling,
making it easy to represent complex relationships and hierarchies.
2. High Performance: Graph databases like Neo4j excel in traversing relationships, making queries
for connected data fast and efficient, even with large datasets.
3. Real-time Insights: Neo4j is well-suited for real-time analytics, recommendation engines, fraud
detection, social network analysis, and other applications that require analyzing relationships
and patterns.
4. Scalability and Agility: Neo4j's architecture supports horizontal scaling and provides agility in
adapting to evolving data structures and query patterns.
Use Cases for Neo4j Graph Databases:
1. Social Networks: Neo4j is commonly used in social networking platforms to model relationships
between users, friends, followers, and content.
2. Recommendation Systems: Graph databases excel in recommendation engines by modeling
user preferences, item relationships, and personalized recommendations.
3. Network and IT Operations: Neo4j is used in network management, IT operations, and
cybersecurity for modeling infrastructure, dependencies, and identifying anomalies.
4. Knowledge Graphs: Neo4j powers knowledge graphs for organizing and connecting diverse
data sources, enabling semantic search and data discovery.

Getting Started with Neo4j:


1. Download and Install Neo4j: Visit the official Neo4j website (https://neo4j.com/) to download
the Neo4j Community Edition or Enterprise Edition based on your requirements and platform.
2. Start Neo4j Server: After installation, start the Neo4j server, which provides a web-based
interface (Neo4j Browser) for interacting with the database and running Cypher queries.
3. Explore Graph Data: Use Neo4j Browser to create nodes, relationships, and properties, and
perform queries using the Cypher query language to explore your graph data.
4. Develop Applications: Integrate Neo4j into your applications using Neo4j's drivers and libraries
available for various programming languages, such as Java, Python, JavaScript, and more.
Practical-7

Aim:- Basic CRUD Operations with Neo4j Graph Databases

Basic CRUD Operations with Neo4j Graph Databases:

Neo4j provides a powerful query language called Cypher for performing CRUD (Create,
Read, Update, Delete) operations on graph data. Below are examples of basic CRUD
operations using Cypher in Neo4j.

1. Create Operation (Create Nodes and Relationships):


● Create a node with properties

CREATE (:Person {name: 'John', age: 30});

2. Read Operation (Retrieve Nodes and Relationships): ● Retrieve all nodes:


MATCH (p:Person) RETURN p;

3. Update Operation (Update Node Properties):


● Update node properties
MATCH (p:Person {name: 'John'}) SET p.age = 31;
4. Delete Operation (Delete Nodes and Relationships):
● Delete a node
MATCH (p:Person {name: 'Alice'}) DELETE p;

You might also like