0% found this document useful (0 votes)
21 views19 pages

No SQL lab manual

The document is a lab manual for the course 'Introduction to NoSQL' covering various NoSQL database types, including document-oriented, key-value, column-family, and graph databases. It includes practical exercises on MongoDB and Cassandra, detailing installation, CRUD operations, data modeling, and Neo4j graph databases. The manual aims to provide students with hands-on experience and understanding of NoSQL technologies for the academic term 2023-2024.

Uploaded by

samidshaikh24
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)
21 views19 pages

No SQL lab manual

The document is a lab manual for the course 'Introduction to NoSQL' covering various NoSQL database types, including document-oriented, key-value, column-family, and graph databases. It includes practical exercises on MongoDB and Cassandra, detailing installation, CRUD operations, data modeling, and Neo4j graph databases. The manual aims to provide students with hands-on experience and understanding of NoSQL technologies for the academic term 2023-2024.

Uploaded by

samidshaikh24
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/ 19

Page | 1

F.D. (MUBIN) Institute of Engineering and Technology


Lab Manual
D.I. Semester: VI
Subject: Introduction to NoSQL (4360704)
Page | 2

CERTIFICATE

This is to certify that Mr./Ms._____________________________________

Enrollment No.

Semester _________ Branch has satisfactorily

completed his/her term work in Course of “Introduction to NoSQL” with subject code

4360704 for the academic term 2023-2024.

Staff In-charge Date of Submission Head of Department


Page | 3

Introduction to NoSQL (4360704) Index

Sr Practical name Page Signature


No. No.

1. Introduction and Types of NoSQL Databases

2. Introduction and Installation of MongoDB

3. Basic CRUD Operations with MongoDB

4. Introduction and Setup of Cassandra

5. Data Modeling and Simple Queries with Cassandra

6. Introduction to Neo4j Graph Databases

7. Basic CRUD Operations with Neo4j Graph


Databases
Page | 4

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.
Page | 5

Column-Family Stores: Column-family stores organize data into columns rather than rows,
making them suitable for handling large-scale, distributed data sets. These databases are
optimized for read-heavy workloads and excel in scenarios requiring efficient storage and
retrieval of large volumes 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 represent and query


relationships between data entities, making them ideal for applications involving
complex interconnections and networks. In graph databases, data is stored as nodes
(entities), edges (relationships), and properties (attributes). This structure enables
powerful querying capabilities for traversing relationships and analyzing connected
data. Graph databases are commonly used in social networks, recommendation
engines, fraud detection, and network analysis. Examples of graph databases include
Neo4j, ArangoDB, and Amazon Neptune (a fully managed graph database service
from AWS)
Page | 6

Practical-2

Aim:- Introduction and Installation of MongoDB.


Page | 7
Page | 8
Page | 9
P a g e | 10

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();
P a g e | 11

OUTPUT:-

OUTPUT:-
P a g e | 12

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
P a g e | 13

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.
P a g e | 14

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:-
P a g e | 15

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:-
P a g e | 16

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.
P a g e | 17

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.
P a g e | 18

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});


P a g e | 19

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