NoSQL Lab Fat
NoSQL Lab Fat
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
•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});
db.MIA1126_hospital.insertMany([
{ name: "Chenchu",
patients: [
],
},
name: "Aravind",
branch: "Chettinad",
patients: [
},
name: "Rahul",
branch: "Apollo",
patients: [
],
])
Display the name of the doctors who are from VIT chettinad branch
db.MIA1126_hospital.find({
"branch": "Chettinad",
"name": "Aravind",
"patients.age": { $gt: 3 }
})
Name: Chenchu Aravind
db.MIA1126.insertMany([
"name": "Chenchu",
"registerNumber": "1126",
"address":"Thazambur chennai"
},
"name": "Aravind",
"registerNumber": "1127",
},
"name": "Pavani",
"registerNumber": "1128",
]);
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" },
{ 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" },
);
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",
"subjectMarks": {
"Math": 90,
"Science": 85,
"History": 78
},
"name": "Aravind",
"studentId": "1127",
"subjectMarks": {
"Science": 92,
"English": 88,
"Art": 75
},
"name": "rahul",
"studentId": "1128",
"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" },
);
Replace the subject “X” with “Y” for example (“Science” with “EVS”) for all the
students.
db.MIA1126.updateMany(
{ "electiveSubjects": "History" },
);
NAME: Chenchu Aravind
RegNo: 20MIA1126
db.MIA1126_student.insertMany([
"registrationNumber": "001",
"name": "CHENCHU",
"program": "M.Tech",
"marks": 45,
"subjects": [
},
"registrationNumber": "002",
"name": "ARAVIND",
"program": "M.Tech",
"marks": 30,
"subjects": [
]
},
"registrationNumber": "003",
"name": "CHEN",
"program": "B.Tech",
"specialization": "CSE",
"marks": 40,
"subjects": [
])
db.MIA1126_student.updateMany(
);
z
(ii) update the marks of students which are less than 50 as 50 for the given student
registration number.
db.MIA1126_student.updateMany(
{ $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.
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
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
2. Display the details of students Program wise and course code wise
3. Display the details of M.Tech students in course wise with marks are in ascending
order
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.
db.MIA1145.find();
Multikey indexing:
Compound key indexing:
Without 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?
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
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 = '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);
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;
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
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'})