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

NoSQL Lab Fat

This document discusses a Nosql lab assignment involving array filters. It shows updates

Uploaded by

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

NoSQL Lab Fat

This document discusses a Nosql lab assignment involving array filters. It shows updates

Uploaded by

Varun Vaishnav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Name: Chenchu Aravind

RegNo: 20MIA1126
NOSQL LAB_1 ASSIGNMENT
1. Create a collection named as student_details to accommodate the required
fields for the below queries with minimum 5 documents.

db. MIA1126_student.insertMany([

{ id: 1, name : 'Chenchu', type: 'Dayscholar', address: 'chennai egmore', year: 3,branch:
'MAI'},

{ id:2, name: 'Aravind',type: 'Hosteller', block: 'A',address: 'chennai srptools', year: 3, branch:
'MAI'},

{ id:3, name: 'vicky', type: 'Hosteller', block: 'B', address: 'chennai perungudi',year: 3, branch:
'MAI'},

{ id:4, name: 'ganesh', type: 'Hosteller', block: 'C',address: 'chennai t.nagar', year: 2, branch:
'MAI'},

{ id:5, name: 'govindha', type: 'Dayscholar', address: 'chennai navalur', year: 2, branch: 'MAI'},

]);

• Display the name of the students who are staying in hostel ‘A’ block

db. MIA1126_student.find({ block:{$eq:'A'}},{_id: 0,name: 1});

•Display the name of the students who are day scholar and come from Egmore,
Chennai,.
db.student_details.find({type:"Dayscholar",address:"chennai egmore"},{_id: 0, name:
1})

•Display the name, address of the students who are 3rd year MAI students
staying in A and B blocks of the hostel
db.
MIA1126_student.find({$and:[{year:{$eq:3}},{branch:{$eq:'MAI'}},{$or:[{block:{$eq:'A'}},{block:{$
eq:'B'}}]}]},{_id: 0,name: 1,address: 1});

2. Develop a hospital management system collection for the below queries.

db.MIA1126_hospital.insertMany([

{ name: "Chenchu",

branch: "VIT Chettinad",

patients: [

{ patientName: "obama", age: 29 },

{ patientName: "Barack", age: 40 },

],

},

name: "Aravind",

branch: "Chettinad",

patients: [

{ patientName: "Narendra", age: 27 },

{ patientName: "Modi", age: 4 },


],

},

name: "Rahul",

branch: "Apollo",

patients: [

{ patientName: "Lal", age: 26 },

{ patientName: "Sastri", age: 6 },

],

])

Display the name of the doctors who are from VIT chettinad branch

db.MIA1126_hospital.find({"branch": "VIT Chettinad"}, {"name": 1})

Display the details of the patients under the doctor "Y"

db.MIA1126_hospital.find({ "name": "Rahul" }, { "patients": 1 })


Display the details of patients who age is greater than 3 in main chettinad hospital
under the given doctor name

db.MIA1126_hospital.find({

"branch": "Chettinad",

"name": "Aravind",

"patients.age": { $gt: 3 }

})
Name: Chenchu Aravind

Reg No: 20MIA1126

NOSQL lab Assignment-2


1.Develop a student collection with primitive data types student name, register
number cat1 mark of nosql and address with minimum 3 documents

db.MIA1126.insertMany([

"name": "Chenchu",

"registerNumber": "1126",

"NoSQL cat1 marks": 85,

"address":"Thazambur chennai"

},

"name": "Aravind",

"registerNumber": "1127",

"NoSQL cat1 marks": 92,

"address": "Perungudi Chennai"

},

"name": "Pavani",

"registerNumber": "1128",

"NoSQL cat1 marks": 78,

"address": "SRP tools Chennai"

]);
2.Update the student name for the given registration number

db.MIA1126.updateOne(

{ "registerNumber": "1127" },
{ $set: { "name": "Rahul" } }

);

Update the address for the given name and show the upsert option with explanation
db.MIA1126.updateOne(

{ "name": "Rahul" },

{ $set: { "address":"Guindy Chennai" } },

{ upsert: true }

);
The upsert option is set to true, which means that if a document with the given
name ("Rahul") doesn't exist, a new document will be inserted with the specified
address (" Guindy Chennai”).

Update the mark of the students for the given name with multi property and provide
suitable explanations

db.MIA1126.updateOne(

{ "name": "Chenchu" },

{ $set: { "NOSQL cat1 marks": 95 } }

);
2. Develop a student collection with appropriate complex data types - use array to
store the list of elective subjects and embedded document to store the
subject_name:mark of the subject. Initialize the collection with minimum 3 documents

db.MIA1126.insertMany([

"name": "Chenchu",

"studentId": "1126",

"electiveSubjects": ["Math", "Science", "History"],

"subjectMarks": {
"Math": 90,

"Science": 85,

"History": 78

},

"name": "Aravind",

"studentId": "1127",

"electiveSubjects": ["Science", "English", "Art"],

"subjectMarks": {

"Science": 92,

"English": 88,

"Art": 75

},

"name": "rahul",

"studentId": "1128",

"electiveSubjects": ["History", "Math", "AI"],

"subjectMarks": {

"History": 80,

"Math": 88,

"AI": 95

]);
Update the mark of a particular student for a particular course for a given student id.

db.MIA1126.updateOne(

{ "studentId": "1126" },

{ $set: { "subjectMarks.Science": 95 } }

);
Replace the subject names with “TOC” for a given student name “X”

db.MIA1126.updateOne(

{ "name": "Chenchu" },

{ $set: { "electiveSubjects": ["TOC", "TOC", "TOC"] } }

);
Replace the subject “X” with “Y” for example (“Science” with “EVS”) for all the
students.

db.MIA1126.updateMany(

{ "electiveSubjects": "History" },

{ $set: { "electiveSubjects.$": "Polity" } }

);
NAME: Chenchu Aravind

RegNo: 20MIA1126

NOSQL LAB ASSIGNMENT-3

Update operations with Array Filter

db.MIA1126_student.insertMany([

"registrationNumber": "001",

"name": "CHENCHU",

"program": "M.Tech",

"specialization": "AI ML",

"marks": 45,

"subjects": [

{ "name": "x", "score": 85 },

{ "name": "y", "score": 75 }

},

"registrationNumber": "002",

"name": "ARAVIND",

"program": "M.Tech",

"specialization": "AI ML",

"marks": 30,

"subjects": [

{ "name": "x", "score": 60 },

{ "name": "y", "score": 70 }

]
},

"registrationNumber": "003",

"name": "CHEN",

"program": "B.Tech",

"specialization": "CSE",

"marks": 40,

"subjects": [

{ "name": "x", "score": 40 },

{ "name": "y", "score": 30 }

])

(i) update the subject name x as y for M.Tech AI ML students

db.MIA1126_student.updateMany(

{ program: "M.Tech", specialization: "AI ML" },

{ $set: { "subjects.$[elem].name": "y" } },

{ arrayFilters: [{ "elem.name": "x" }] }

);
z

(ii) update the marks of students which are less than 50 as 50 for the given student
registration number.
db.MIA1126_student.updateMany(

{ registrationNumber: "003", marks: { $lt: 50 } },

{ $set: { marks: 50 } }

);

(iii) write about the purpose of arrayFilters option in Update command (Maximum 3
lines)

The arrayFilters option in the MongoDB update command enables precise targeting of specific array
elements that match given conditions. It ensures focused updates within arrays, allowing
modifications to be applied only to elements that satisfy specified criteria.

(iv) create a json file with 3 student details and name the file as your
registration_number.json . Then move the file to new colloction in mongodb through
mongo import command. Make sure that mongoimport command should be executed
in normal command prompt not inside the mongo shell.
20MIA1145
Varun Vaishnav S

CSE3086 LAB-4
Develop the minimal student information system to answer the below queries.

db.students1145.insertMany([
{"student_id": "1145","name": "Varun","electives": [{"name": "NoSQL","score": 62},
{"name": "TARP","score": 69}]},
{"student_id": "1156","name": "Maline","electives": [{"name": "NoSQL","score": 88},
{"name": "TARP","score": 88}]},
{"student_id": "1001","name": "Jai","electives": [{"name": "NoSQL","score": 98}]}

]);

1. List out the students who have taken only nosql elective

This query retrieves students who have enrolled in the "NoSQL" elective course while
excluding those who have taken any other elective courses. It ensures that the students being
returned have exclusively chosen the "NoSQL" elective without any additional elective
courses in their course list.

2. List out the students who has nosql taken elective


It provides a list of students who have specifically opted for the "NoSQL" course in their
curriculum.

3. It provides a list of students who have specifically opted for the "NoSQL" course in
their curriculum and scored between 25 and 30

The intention behind this query is to find students who have obtained marks within the range
of 25 to 30 in the "NoSQL" elective course. It aims to locate and present students who fall
within this specific score range in this particular course.

4. List out the students who have not opted TARP course in this semester

This query seeks students who have not selected the "TARP" course during the current
semester. It aims to provide a list of students who did not enroll in the "TARP" course for the
semester under consideration.

5. List out the students who have scored >30 as first index mark
This query is to find students whose first index mark (the mark for the first course) is greater
than 30. It identifies and presents students whose performance in the initial course has
exceeded the specified threshold.

6. List out the students who have taken only 2 electives in this semester.

This query retrieves students who have chosen exactly two elective courses in the current
semester. It ensures that the returned students have selected precisely two elective courses
and no more for their course load in this specific semester.
Varun Vaishnav S

20MIA1145

NOSQL LAB 5

MongoDB and Map Reduce

1.Write a map reduce code to display the sum of marks obtained by the students in
department wise

db.MIA1145.aggregate([{$unwind:"$course"},{$group:{_id:"$department",total_marks: {
$sum: "$course.marks" }}}]);
2. Simulate the word count program using mongoDB – mapreduce

MongoDB with single and pipeline Aggregarion operation

I. List the student names in alphabetical order

db.MIA1145.find({}, { _id: 0, name: 1 }).sort({ name: 1 });

2. Display the details of students Program wise and course code wise

db.MIA1145.aggregate([{ $unwind: "$course" },{$pStudentdetails>


db.MIA1145.aggregate([{ $unwind: "$course" },{$project: {_id: 0,name: 1,program: 1,sub:
"$course.sub",course_code: "$course.cource_code",marks: "$course.marks"}},{ $sort: {
proprogram: 1, course_code: 1 } }]);

3. Display the details of M.Tech students in course wise with marks are in ascending
order

db.MIA1145.aggregate([{ $match: { program: "MIA" } },{ $unwind: "$course" },{$project:


{_id: 0,name: 1,program: 1,subsub:
"$course.sub",course_code:"$course.cource_code",marks: "$course.marks"}},{ $sort: {
program: 1, course_code: 1, marks: 1 } }]);

4. Display the total marks scored by each programme in ascending order

db.MIA1145.aggregate([{ $unwind: "$course" },{$group: {_id: "$program",total_marks: {


$sum: "$course.marks" }}},{ $sort: { total_marks: 1 } }]);
5. Group the details of students in programme wise and then in each programme, group
the details of students in course code wise.

db.MIA1145.aggregate([{ $unwind: "$course" },{$group: {_id: {program:


"$program",course_code: "$course.cource_code"},MIA1145: { $push: "$$ROOT"
}}},{$group: {_id: "$_id.program",courses: {$push: {course_code:
"$_id.course_code",MIA1145: "$MIA1145"}}}}]);
NOSQL LAB-6
Varun Vaishnav S
20MIA1145

1.Design the appropriate student collection and apply 4 types of indexing (single key
field indexing, single key field indexing with embedded data type, multikey indexing and
compound key indexing). Perform the find and sort operations. Also analyse the
performance of queries with and without indexing.

Single key field indexing:

db.MIA1145.find();

db.MIA1145.createIndex({ "Name": 1 });


Single key field indexing with embedded data type:

Multikey indexing:
Compound key indexing:

Without Index:

With Single Key Field Index on Embedded Data Type:


With Compound Key Index:

Analysing:
2. Develop a Map Reduce method in Mongo dB to display the 2nd highest salary in each
department. Design the collection accordingly and store the output into the new
collection.

3. Design a python program to display the details of students from MongoDB students
collection
CSE3086-NoSQL
Lab-7

Varun Vaishnav S
20MIA1145

1. Create a new capped collection to store the students data and check the size
property – how it works?

2. Convert the normal collection to a capped collection and analyze how it


works in case of size is different between two collections.
3. Create a collection with ttl index and show the execution after time expires.

4. Convert the size property of existing capped collection to n if it is capped


collection.
5. Create a collection for employee details with dept as an index key with hide
property analyze the performance.

6. Display the highest salary department wise using python and mongodb
CSE3086 NoSQL
LAB-8

Varun Vaishnav S
20MIA1145

Create Business Analytics as keyspace with student_regno as table name. It should have
the
following info
● Name
● Id
● Hobbies of student - set
● Cat1 marks of all subjects in this sem - subject name : mark -map
● No of days absent in each course from day1 to last class of cat1 for all the subjects - list
1. Insert min 2 records
2. Perform update operation on all fields of student table with all attributes
3. Do the delete operations for the students whose id is equal to 100
4. Display the student details who are present in all classes from day 1 to last day of cat 1
classes for all subjects

This is how we achieve all the operations using cassandra


NoSQL LAB-10

VARUN VAISHNAV S
20MIA1145
Creating table:
cqlsh> USE MIA1145;
cqlsh:mia1145> CREATE TABLE IF NOT EXISTS mia1145_lab(student_id UUID PRIMARY
KEY,student_name TEXT,cat1_marks map<TEXT,INT>,cat2_marks map<TEXT,INT>);
Inserting values:
cqlsh:mia1145> INSERT INTO
mia1145_lab(student_id,student_name,cat1_marks,cat2_marks)
VALUES(uuid(),'varun',{'nosql':65,'toc':65,'iot':45},{'nosql':54,'toc':67,'iot':89});
cqlsh:mia1145> INSERT INTO
mia1145_lab(student_id,student_name,cat1_marks,cat2_marks)
VALUES(uuid(),'sarvesh',{'nosql':42,'toc':55,'iot':89},{'nosql':76,'toc':64,'iot':65});
cqlsh:mia1145> INSERT INTO
mia1145_lab(student_id,student_name,cat1_marks,cat2_marks)
VALUES(uuid(),'maline',{'nosql':82,'toc':75,'iot':89},{'nosql':86,'toc':94,'iot':96});
Creating function and displaying results:
cqlsh:mia1145> create or replace function find_highest(cat1_marks
map<text,int>,cat2_marks map<text,int>)
... called on null input returns text language java as 'int max1 = 0; int max2 =0;
... for(Object value : cat1_marks.values()){ if(value != null && (Integer)value > max1) {
... max1 = (Integer)value;}} for(Object value: cat2_marks.values()){ if(value != null &&
... (Integer)value > max2){ max2 = (Integer)value;}} return
... String.valueOf(max1)+"|"+String.valueOf(max2);';
cqlsh:mia1145>
cqlsh:mia1145> SELECT student_id, student_name, find_highest(Cat1_marks,Cat2_marks) as
highest FROM mia1145_lab;
NoSQL Lab-11

Varun Vaishnav S
20MIA1145

1.
CREATE (p1:Person{name: "Micheal"}),(p2:Person{name: "Jennifer"}), (p3:Company{
name:"Neo4j"}),(p4:Technology {type:"Graphs"});
MATCH (a:Person),(b:Person) where a.name="Micheal" and b.name = "Jennifer" crea
te (b)-[:IS_FRIENDS_WITH {since:2018}]->(a);
MATCH (a:Technology),(b:Person) where a.type="Graphs" and b.name = "Jennifer" c
reate (b)-[:LIKES]->(a);
MATCH (a:Company),(b:Person) where a.name="Neo4j" and b.name = "Jennifer" cre
ate (b)-[:WORKS_FOR]->(a);
MATCH(n) RETURN n;
2.
CREATE(s1:Student{name:"varun"}),(s2:Student{name:"maline"}),(s3:Student{name:"sarvesh
"}),(s4:Student{name:"jai"}),(t1:Teacher{name:"abc"}),(t2:Teacher{name:"xyz"});

MATCH (a:Teacher),(b:Student) WHERE a.name = 'abc' and b.name = 'varun'


CREATE (b)-[:Register{slot:'c1'}]->(a);

MATCH (a:Teacher),(b:Student) WHERE a.name = 'abc' and b.name = 'maline' CREATE (b)-
[:Register{slot:'c2'}]->(a);

MATCH (a:Teacher),(b:Student) WHERE a.name = 'xyz' and b.name = 'sarvesh' CREATE (b)-
[:Register{slot:'c2'}]->(a);

MATCH (a:Teacher),(b:Student) WHERE a.name = 'xyz' and b.name = 'jai'


CREATE (b)-[:Register{slot:'c1'}]->(a);
MATCH (n) RETURN n;
MATCH (a:Student)-[r:Register{slot:'c1'}]->(b:Teacher{name:"abc"}) RETURN a.name;

MATCH (a:Student)-[r:Register{slot:'c2'}]->(b:Teacher{name:"xyz"}) RETURN a.name;

3.
LOAD CSV WITH HEADERS from 'file:///student20mia1145.csv' as row with row wher
e row.Source is not null
MERGE (n:Source {Name: row.Source})
MERGE (m: Target {Name: row.Target})
MERGE (n)-[:TO {dist: row.Distance}]->(m)
4.
MATCH (Person{name:"Jennifer"})-[r:IS_FRIENDS_WITH]->() DELETE r;

MATCH (n:Company{name:'Neo4j'}) DETACH DELETE n;


CSE3086 - NoSQL Lab-12

Varun Vaishnav S
20MIA1145

1.Supplier - item information system - create nodes of supplier and item with suitable
properties. Create the relationship between with the property of which year they have
started supplying items

create (n1:item{name:'SSD', id:1, qty:30}), (n2:item{name:'Laptop', id:2,


qty:50}),(n3:item{name:'Phone', id:3, qty:46}),(n4:item{name:'PC', id:4, qty:98}),
(s1:supplier{name:'x',address:'Chennai'}),(s2:supplier{name:'xx',address:'Mumbai'})

match (a:item),(b:supplier) where a.name = 'Laptop' and b.name ='x' create(b)-


[:supplies{since:2010}]->(a)

match (a:item),(b:supplier) where a.name = 'Phone' and b.name ='x' create(b)-


[:supplies{since:2023}]->(a)

match (a:item),(b:supplier) where a.name = 'Laptop' and b.name ='xx' create(b)-


[:supplies{since:2020}]->(a)

match (a:item),(b:supplier) where a.name = 'Phone' and b.name ='xx' create(b)-


[:supplies{since:2021}]->(a)

match (a:item),(b:supplier) where a.name = 'PC' and b.name ='xx' create(b)-


[:supplies{since:2022}]->(a)

match (a:item),(b:supplier) where a.name = 'SSD' and b.name ='xx' create(b)-


[:supplies{since:2021}]->(a)
a. Display the supplier details for the given item name

b. Display the list of suppliers

c. Display the list of items

d. Display the name of item supplied by the supplier since 2023


e. Display the item details supplied by the supplier from chennai city with a name "x"

1. Create nodes for emp and dept with suitable properties. Create the relationship
between with the property of which year they joined in the department with what
designation.
create (e1:emp{name:'x',emp_id:1}),(e2:emp{name:'y',emp_id:2}),(e3:emp{name:'z',emp_id:

3}),(d1:dep{name:'NOSQL'}),(d2:dep{name:'DeanAcad'})

match(a:emp),(b:dep) where a.name = 'x' and b.name = 'NOSQL' create(a)-


[r:works{joined:2020,designation:'senior-assistant'}]->(b)

match(a:emp),(b:dep) where a.name = 'y' and b.name = 'NOSQL' create(a)-


[r:works{joined:2023,designation:'manager'}]->(b)

match(a:emp),(b:dep) where a.name = 'z' and b.name = 'DeanAcad' create(a)-


[r:works{joined:2023,designation:'junior-assistant'}]->(b)

a. Display the details of emp who works in accounts dept.


b. Display the dept name for the emp 'y'

c. Display the employee who has joined in 2023 as junior assistant.

You might also like