0% found this document useful (0 votes)
17 views46 pages

NoSQL Lab Assignment Overview

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

Uploaded by

Varun Vaishnav
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)
17 views46 pages

NoSQL Lab Assignment Overview

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

Uploaded by

Varun Vaishnav
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

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 [Link]', 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",

"[Link]": { $gt: 3 }

})
Name: Chenchu Aravind

Reg No: 20MIA1126

NOSQL lab Assignment-2


[Link] a student collection with primitive data types student name, register
number cat1 mark of nosql and address with minimum 3 documents

[Link]([

"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"

]);
[Link] the student name for the given registration number

[Link](

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

);

Update the address for the given name and show the upsert option with explanation
[Link](

{ "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

[Link](

{ "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

[Link]([

"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.

[Link](

{ "studentId": "1126" },

{ $set: { "[Link]": 95 } }

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

[Link](

{ "name": "Chenchu" },

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

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

[Link](

{ "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": "[Link]",

"specialization": "AI ML",

"marks": 45,

"subjects": [

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

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

},

"registrationNumber": "002",

"name": "ARAVIND",

"program": "[Link]",

"specialization": "AI ML",

"marks": 30,

"subjects": [

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

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

]
},

"registrationNumber": "003",

"name": "CHEN",

"program": "[Link]",

"specialization": "CSE",

"marks": 40,

"subjects": [

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

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

])

(i) update the subject name x as y for [Link] AI ML students

db.MIA1126_student.updateMany(

{ program: "[Link]", specialization: "AI ML" },

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

{ arrayFilters: [{ "[Link]": "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.

[Link]([
{"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

[Link] a map reduce code to display the sum of marks obtained by the students in
department wise

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

MongoDB with single and pipeline Aggregarion operation

I. List the student names in alphabetical order

[Link]({}, { _id: 0, name: 1 }).sort({ name: 1 });

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

[Link]([{ $unwind: "$course" },{$pStudentdetails>


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

3. Display the details of [Link] students in course wise with marks are in ascending
order

[Link]([{ $match: { program: "MIA" } },{ $unwind: "$course" },{$project:


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

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

[Link]([{ $unwind: "$course" },{$group: {_id: "$program",total_marks: {


$sum: "$[Link]" }}},{ $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.

[Link]([{ $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

[Link] 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:

[Link]();

[Link]({ "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
... [Link](max1)+"|"+[Link](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 [Link]="Micheal" and [Link] = "Jennifer" crea
te (b)-[:IS_FRIENDS_WITH {since:2018}]->(a);
MATCH (a:Technology),(b:Person) where [Link]="Graphs" and [Link] = "Jennifer" c
reate (b)-[:LIKES]->(a);
MATCH (a:Company),(b:Person) where [Link]="Neo4j" and [Link] = "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 [Link] = 'abc' and [Link] = 'varun'


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

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

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

MATCH (a:Teacher),(b:Student) WHERE [Link] = 'xyz' and [Link] = 'jai'


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

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

3.
LOAD CSV WITH HEADERS from '[Link] as row with row wher
e [Link] is not null
MERGE (n:Source {Name: [Link]})
MERGE (m: Target {Name: [Link]})
MERGE (n)-[:TO {dist: [Link]}]->(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

[Link] - 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 [Link] = 'Laptop' and [Link] ='x' create(b)-


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

match (a:item),(b:supplier) where [Link] = 'Phone' and [Link] ='x' create(b)-


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

match (a:item),(b:supplier) where [Link] = 'Laptop' and [Link] ='xx' create(b)-


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

match (a:item),(b:supplier) where [Link] = 'Phone' and [Link] ='xx' create(b)-


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

match (a:item),(b:supplier) where [Link] = 'PC' and [Link] ='xx' create(b)-


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

match (a:item),(b:supplier) where [Link] = 'SSD' and [Link] ='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 [Link] = 'x' and [Link] = 'NOSQL' create(a)-


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

match(a:emp),(b:dep) where [Link] = 'y' and [Link] = 'NOSQL' create(a)-


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

match(a:emp),(b:dep) where [Link] = 'z' and [Link] = '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.

Common questions

Powered by AI

MongoDB's array filters allow for precise targeting of elements within an array that match specified conditions, enabling selective updates. For instance, to change the subject name 'x' to 'y' for M.Tech AI ML students, the array filter is used to update only those elements where the name is 'x', thus avoiding changes to all subjects indiscriminately. This ensures accuracy and specificity in data manipulation .

Converting a normal collection to a capped collection in MongoDB can pose challenges such as data loss if the collection's size exceeds the capped limit or performance degradation due to maintaining size constraints. These issues can be mitigated by carefully analyzing the data size to ensure compatibility with the capped size before conversion and by considering the growth patterns and data retention needs. Additionally, conducting performance tests can prevent unexpected consequences on query efficiency and application functionality .

Using Python with MongoDB is significant for educational data management as it combines Python's flexible programming capabilities with MongoDB's powerful NoSQL database features. Python scripts can efficiently retrieve and process data, allowing educational apps to present dynamic query results, perform data analyses, and render visualizations. This integration simplifies tasks such as querying student records, calculating academic statistics, and generating reports, making it crucial for optimized educational data workflows .

The 'upsert' option in MongoDB update command allows for either updating an existing document if it matches the query or inserting a new document if no such document exists. When updating a student's address with upsert set to true, if the student's name does not already exist in the collection, a new document will be created with the specified address. In the given example, if a student named "Rahul" does not exist, a document with name "Rahul" and the address "Guindy Chennai" is inserted .

Capped collections in MongoDB are advantageous for managing student data as they provide a fixed-size storage solution, maintaining insertion order and automatically removing the oldest documents when the size limit is exceeded. This helps in scenarios like logging or recording events where only the most recent information is needed. The size property ensures the collection remains within a pre-defined storage limit, facilitating efficient space management and query performance by keeping the dataset manageable .

CSV import operations into Neo4j are beneficial for managing large datasets by facilitating bulk data transfer and initial graph structuring in a university setting. For student relationships, importing CSV files enables the quick creation of nodes and relationships representing registrational data, course enrolments, and other academic interactions. This process ensures large-scale data import without manual entry, maintaining data integrity and enabling complex queries about student networks and course participation .

In Neo4j, relationships between entities like students and teachers or suppliers and items enhance data connectivity by explicitly defining how entities are interrelated. This model facilitates rich queries, as relationships can be directly traversed without joins, improving retrieval speed and complexity. It allows for complex queries about relational paths, such as finding all students registered with a particular teacher or suppliers of a specific item, thus enabling powerful graph-based insights in educational systems .

MapReduce in MongoDB is used to perform complex aggregation tasks by processing and reducing data across documents. For calculating department-wise total marks, the MapReduce operation unwinds the course array for each student and groups the data by department, then sums up the marks. This approach enables efficient aggregation over large datasets, allowing educators to analyze overall departmental performance, identify trends, and make informed decisions based on aggregated data .

Indexing in MongoDB improves query performance by allowing the database to quickly locate and access the data rather than scanning the entire collection. Different indexing types include single key field indexing, which indexes a single field; embedded data type indexing, which focuses on fields within a document structure; multi-key indexing for array fields; and compound key indexing on multiple fields. These indexing strategies tailor to various query needs and enhance data retrieval efficiency .

Using embedded documents and arrays in MongoDB significantly enhances data modeling for educational contexts by naturally aligning with the hierarchical and multi-dimensional nature of such data. For instance, storing student elective courses and their respective scores is efficiently managed in arrays and embedded documents, enabling a compact structure that mirrors real-world relationships. This design reduces the need for joins and improves read and write operations by co-locating related data .

You might also like