Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

LAB MANUAL Advanced ADBMS

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

DEPARTMENT OF INFORMATION

TECHNOLOGY

LAB MANUAL

CLASS:TE(IT)
TERM:I
SUBJECT: LABORATORY PRACTICE-I (ADBMS)
COURSE: 2019 PATTERN
ACADEMIC YEAR: 2022-23

Laboratory Practice-I/ADBMS/TE-IT Page 1


INDEX

Sr.No. Content Page


no.
1 Department vision ,Mission, Program Educational 3 TO 4
Objectives,Program Specific Outcomes and Program
Outcomes
2 Syllabus 5 T0 8
3 Practical List 9

3 Assignment No:-1

Create a database with suitable example using MongoDB 10 to 11


and implement

Group-A)Inserting, saving & Removingdocument 12 TO 17

Group-B)Updating document 18 TO 19

Group-C)Execute at least 10 queries on any suitable 20 TO 22


MongoDB database.

4 Assignment No:-2 23 TO 26

Implement Map-reduce and aggregation, indexing with


suitable example inMongoDB.

27
5 Assignment No:-3
Case Study: Design conceptual model using Star and
Snowflake schema for any one database.

28
6 Assignment No:-4
Mini Project

Laboratory Practice-I/ADBMS/TE-IT Page 2


Vision

To equip students with core and state of the art Information Technologies.

Mission
Imparting knowledge of Information Technology and teaching its application
through innovativepractices and to instil high morale, ethics, lifelong learning skills,
concern for the society and environment.

Program Educational Objectives

I. To prepare students to identify, formulate, and solve


multifaceted and complex ITproblems.
II. To teach core professional skills with latest information
technologies that preparesstudents for immediate employment in
Information Technology Industry.
III. To teach students soft skills that prepares them for leadership
roles along diversecareer paths.
IV. To make students aware of their social responsibilities in building the
nation/society.

Program Specific Outcome

Graduates will be able to

1. Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of
complex engineering problems.[Engineering knowledge]
2. Identify, formulate, research literature, and analyse complex
engineering problems reaching substantiated conclusions using
first principles of mathematics, natural sciences, and engineering
sciences.[Problem analysis]

3. Design solutions for complex engineering problems and design


system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the
cultural, societal, and environmental
considerations.[Design/development of solutions]
4. Use research-based knowledge and research methods including
Laboratory Practice-I/ADBMS/TE-IT Page 3
design of experiments, analysis and interpretation of data, and
synthesis of the information to provide valid conclusions.[Conduct
investigations of complex problems]
5. Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and
modelling to complex engineering activities with an understanding
of the limitations. [Modern tool usage]
6. Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering
practice.[The engineer and society]
7. Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable
development.[Environment and sustainability]
8. Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.[Ethics]
9. Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.[Individual and
team work]
10. Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able
to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive
clear instructions.[Communication]
11. Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in
multidisciplinary environments.[Project management and finance]
12. Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context
of technological change.[Life-long learning]

Laboratory Practice-I/ADBMS/TE-IT Page 4


Savitribai Phule Pune University, Pune
Third Year Information Technology (2019
Course)
314448 (B) : Laboratory Practice-I (ADBMS)
Teaching Scheme: Credit Scheme Examination Scheme:
Practical (PR) :4 PR : 25 Marks
hrs/week 02 Credits TW : 25 Marks
Prerequisites:
1. Database Management System
Course Objectives:
1. To learn and understand Database Modeling, Architectures.
2. To learn and understand Advanced Database Programming Frameworks.
3. To learn NoSQL Databases (Open source) such as MongoDB.
4. To design and develop application using NoSQL Database.
5. To design data warehouse schema for given system.
Course Outcomes:
On completion of the course, students will be able to
CO1: Apply advanced Database ProgramminLanguages.
CO2: Apply the concepts of NoSQL Databases.
CO3: Install and configure database systems.
CO4: Populate and query a database using MongoDB commands.
CO5: Design data warehouse schema of any one real-time: CASE STUDY
CO6: Develop small application with NoSQL Database for back-end.

Guidelines for Instructor's


Manual
The faculty member should prepare the laboratory manual for all the experiments and it should
bemade available to students and laboratory instructor/Assistant.
Guidelines for Student's Lab
Journal
1. Student should submit term work in the form of handwritten journal based on specified
list ofassignments.
2. Practical Examination will be based on all the assignments in the lab manual
3. Candidate is expected to know the theory involved in the experiment.
4. The practical examination should be conducted if and only if the journal of the
candidate iscomplete in all respects.

Laboratory Practice-I/ADBMS/TE-IT Page 5


Guidelines for Lab /TW Assessment

1. Examiners will assess the student based on performance of students considering the
parameters such as timely conduction of practical assignment, methodology adopted for
implementation of practical assignment, timely submission of assignment in the form of
handwritten write-up alongwith results of implemented assignment, attendance etc.
2. Appropriate knowledge of usage of software and hardware related to respective laboratory
shouldbe checked by the concerned faculty member.
3. As a conscious effort and little contribution towards Green IT and environment awareness,
attachingprinted papers of the program in journal may be avoided. There must be hand-written
write-ups for every assignment in the journal. The DVD/CD containing student’s programs
should be attached to the journal by every student and same to be maintained by
department/lab In- charge is highly encouraged. For reference one or two journals may be
maintained with program prints at Laboratory.

Guidelines for Laboratory Conduction


1. Group A assignments are compulsory and should be performed by individual student.
2. Group B case study may be performed in group of 3/4.
3. Mini project of Group C can be implemented using any suitable front-end. But back-end
must beMongoDB.
Guidelines for Practical Examination
1. Practical Examination will be based on the all topics covered.
2. Examiners will judge the understanding of the practical performed in the examination by
asking some questions related to theory & implementation of experiments he/she has carried
out.
List of Laboratory Assignments
Group A : MongoDB

Laboratory Practice-I/ADBMS/TE-IT Page 6


1. Create a database with suitable example using MongoDB and implement
 Inserting and saving document (batch insert, insert validation)
 Removing document
 Updating document (document replacement, using modifiers, up inserts,
updatingmultipledocuments, returning updated documents)
 Execute at least 10 queries on any suitable MongoDB database that demonstrates
following:
a. Find and find One (specific values)
b. Query criteria (Query conditionals, OR queries, $not, Conditional
semantics) Type-specific queries (Null, Regular expression,
Queryingarrays)
c. $ where queries
d. Cursors (Limit, skip, sort, advanced quer

2. Implement Map-reduce and aggregation, indexing with suitable example in


MongoDB.Demonstrate the following:
 Aggregation framework
 Create and drop different types of indexes and explain () to show the advantage of
theindexes.
3. Case Study: Design conceptual model using Star and Snowflake schema for any one database.
4. Mini Project
Pre-requisite: Build the mini project based on the requirement document and design prepared as
apart of Database Management Lab in second year.
1. Form teams of around 3 to 4 people.
2. Develop the application:Build a suitable GUI by using forms and placing the controls on it for
any application. Proper data entryvalidations are expected.Add the database connection with
front end. Implement the basic CRUD operations.
3. Prepare and submit report to include: Title of the Project, Abstract, List the hardware
and software requirements at the backend and at the front end, Source Code , Graphical
UserInterface, Conclusion.

Reference Books:
1. Silberschatz A., Korth H., Sudarshan S., "Database System Concepts", 6thEdition, McGraw
HillPublishers, ISBN 0-07-120413-X.
2. Kristina Chodorow, MongoDB The definitive guide, O’Reilly Publications, ISBN:978-93-5110-
269-4,2nd Edition.
3. Jiawei Han, Micheline Kamber, Jian Pei “Data Mining: concepts and techniques”, 2nd
Edition,Publisher: Elsevier/Morgan Kaufmann.
4. http://nosql-database.org/.

Laboratory Practice-I/ADBMS/TE-IT Page 7


2. Create a database with suitable example using MongoDB and implement
 Inserting and saving document (batch insert, insert validation)
 Removing document
 Updating document (document replacement, using modifiers, up inserts,
updatingmultipledocuments, returning updated documents)
 Execute at least 10 queries on any suitable MongoDB database that demonstrates
following:
a. Find and find One (specific values)
b. Query criteria (Query conditionals, OR queries, $not, Conditional
semantics) Type-specific queries (Null, Regular expression,
Queryingarrays)
c. $ where queries
d. Cursors (Limit, skip, sort, advanced quer

5. Implement Map-reduce and aggregation, indexing with suitable example in


MongoDB.Demonstrate the following:
 Aggregation framework
 Create and drop different types of indexes and explain () to show the advantage of
theindexes.
6. Case Study: Design conceptual model using Star and Snowflake schema for any one database.
7. Mini Project
Pre-requisite: Build the mini project based on the requirement document and design prepared as
apart of Database Management Lab in second year.
4. Form teams of around 3 to 4 people.
5. Develop the application:
Build a suitable GUI by using forms and placing the controls on it for any application. Proper data
entryvalidations are expected.
Add the database connection with front end. Implement the basic CRUD operations.
6. Prepare and submit report to include: Title of the Project, Abstract, List the hardware
and software requirements at the backend and at the front end, Source Code , Graphical
UserInterface, Conclusion.

Reference Books:
5. Silberschatz A., Korth H., Sudarshan S., "Database System Concepts", 6thEdition, McGraw
HillPublishers, ISBN 0-07-120413-X.
6. Kristina Chodorow, MongoDB The definitive guide, O’Reilly Publications, ISBN:978-93-5110-
269-4,2nd Edition.
7. Jiawei Han, Micheline Kamber, Jian Pei “Data Mining: concepts and techniques”, 2nd
Edition,Publisher: Elsevier/Morgan Kaufmann.
8. http://nosql-database.org/.

Laboratory Practice-I/ADBMS/TE-IT Page 8


Sr.No. Practical
List

1 Assignment No:-1

Create a database with suitable example using MongoDB and implement

Group-A)Inserting and saving document (batch insert, insert


validation)Removing document

Group-B)Updating document (document replacement, using modifiers, up


inserts,updating multiple documents, returning updated documents)

Group-C) Execute at least 10 queries on any suitable MongoDB database that


demonstrates following

2 Assignment No:-2
Implement Map-reduce and aggregation, indexing with suitable example inMongoDB.

3 Assignment No:-3
Case Study: Design conceptual model using Star and Snowflake schema for any one database.

4 Assignment No:-4

Mini Project

Laboratory Practice-I/ADBMS/TE-IT Page 9


Assignment No-1

Title:- Create a database with suitable example using MongoDB and implement

Objective: To Study of MongoDB

Prerequisite:- Basic database concept.

Theory:- MongoDB is a cross-platform, document oriented database that provides,


high performance, high availability, and easy scalability. MongoDB works on concept
ofThe following table shows the relationship of RDBMS terminology with MongoDB.

RDBMS MongoDB

Database Database

Table Collection

Tuple/Row Document

column Field

Table Join Embedded


Documents
Primary Key (Default key _id
Primary Key
provided by
mongodb itself)
Database Server and Client

Mysqld/Oracle mongod

mysql/sqlplus mongo

Laboratory Practice-I/ADBMS/TE-IT Page 10


Fig:- MongoDB Document

 Advantages of MongoDB over RDBMS


 Schema less: MongoDB is a document database in which one
collection holds different documents. Number of fields, content and
size of the document can differfrom one document to another.

 Structure of a single object is clear.

 No complex joins.

 Deep query-ability. MongoDB supports dynamic queries on


documents using a document-based query language that's nearly
as powerful as SQL.

 Why Use MongoDB?


 Document Oriented Storage: Data is stored in the form of JSON style
documents.
 Index on any attribute
 Replication and high availability
 Auto-sharding
 Rich queries
 Fast in-place updates
 Professional support by MongoDB

 Where to Use MongoDB?


 Big Data
 Content Management and Delivery
 Mobile and Social Infrastructure
 User Data Management
 Data Hub

Laboratory Practice-I/ADBMS/TE-IT Page 11


Assignment No -1-A

(Inserting and saving document (batch insert, insert validation) ,Removing


document)

To create a database in MongoDB.

The use Command

MongoDB use DATABASE_NAME is used to create database. The command will create
anew database if it doesn't exist, otherwise it will return the existing database..

Syntax

use DATABASE_NAME

To check your currently selected database, use the command db

>db
mydb

If you want to check your databases list, use the command show dbs.

>show dbs

local 0.78125GB
test 0.23012GB

In MongoDB default database is test. If you didn't create any database, then
collectionswill be stored in test database.

 To delete or drop database in MongoDB


The dropDatabase() Method

Laboratory Practice-I/ADBMS/TE-IT Page 12


MongoDB db.dropDatabase() command is used to drop a existing database.

Syntax

Basic syntax of dropDatabase() command is as follows:

db.dropDatabase()

This will delete the selected database. If you have not selected any database, then it
willdelete default 'test' database.

Eg. If you want to delete new database <mydb>, then dropDatabase() command would
beas follows:

>use mydb
switched to db mydb
>db.dropDatabase()
>{ "dropped" : "mydb", "ok" : 1 }
>

 To create a collection using MongoDB.

The createCollection() Method

MongoDB db.createCollection(name, options) is used to create collection.

Syntax

Basic syntax of createCollection() command is as follows:

db.createCollection(name, options)

In the command, name is name of collection to be created. Options is a document


andis used to specify configuration of collection.

Parameter Type Description

Laboratory Practice-I/ADBMS/TE-IT Page 13


Name String Name of the collection to be created

Options Document (Optional) Specify options about memory


size and indexing

Examples

Basic syntax of createCollection() method without options is as follows:

>use test
switched to db test
>db.createCollection("mycollection")
{ "ok" : 1 }
>

You can check the created collection by using the command show collections.

>show collections
mycollection
system.indexes

In MongoDB, you don't need to create collection. MongoDB creates collection


automatically, when you insert some document.

>db.tutorialspoint.insert({"name" : "tutorialspoint"})
>show collections
mycol
mycollection
system.indexes
tutorialspoint
>

 To drop a collection using MongoDB


The drop() Method

MongoDB's db.collection.drop() is used to drop a collection from the database.

Laboratory Practice-I/ADBMS/TE-IT Page 14


Syntax

db.COLLECTION_NAME.drop()

Example

drop the collection with the name mycollection.

>db.mycollection.drop()
true
>

 To insert document
To insert data into MongoDB collection, you need to use MongoDB's insert()
or save()method.

Syntax

The basic syntax of insert() command is as follows −

>db.COLLECTION_NAME.insert(document)

Example:-

>db.mycol.insert({

_id: ObjectId(7df78ad8902c),title: 'MongoDB Overview',

description: 'MongoDB is no sql database',

})

Here mycol is our collection name, as created in the previous. If the collection doesn't
exist in the database, then MongoDB will create this collection and then insert a
document into it.

In the inserted document, if we don't specify the _id parameter, then MongoDB assigns
aunique ObjectId for this document.

_id is 12 bytes hexadecimal number unique for every document in a collection. 12


bytes are divided as follows −

Laboratory Practice-I/ADBMS/TE-IT Page 15


_id: ObjectId(4 bytes timestamp, 3 bytes machine id, 2 bytes process id, 3
bytes incrementer)

To insert multiple documents in a single query, you can pass an array of documents
ininsert() command.

Example:

>db.post.insert([

title: 'MongoDB Overview',

description: 'MongoDB is no sql database',by: 'tutorials point',

},

title: 'NoSQL Database',

description: 'NoSQL database doesn't have tables',by: 'tutorials point',

])

To insert the document you can use db.post.save(document) also. If you don't specify
_id in the document then save() method will work same as insert() method. If the save()
method.

MongoDB Save() Method

The save() method replaces the existing document with the new document passed in thesave() method.

Syntax

The basic syntax of MongoDB save() method is −

>db.COLLECTION_NAME.save({_id:ObjectId(),NEW_DATA})

Laboratory Practice-I/ADBMS/TE-IT Page 16


Following example will replace the document with the _id '5983548781331adf45ec7'.

>db.mycol.save(
{
"_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point New
Topic",
"by":"Tutorials Point"
}
)
>db.mycol.find()
{ "_id" : ObjectId(5983548781331adf45ec5), "title":"Tutorials Point New Topic",
"by":"Tutorials Point"}
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
>

Conclusion:Thus ,we have studied about how to create and save document in
Mongodb.

Laboratory Practice-I/ADBMS/TE-IT Page 17


Assignment No-1-B

Updating document (document replacement, using modifiers, up inserts,


updating multiple documents, returning updated documents)

Theory:-

MongoDB's update() and save() methods are used to update document into a collection.
The update() method updates the values in the existing document while the save()
methodreplaces the existing document with the document passed in save() method.

MongoDB Update() Method

The update() method updates the values in the existing document.

The basic syntax of update() method is as follows:

>db.COLLECTION_NAME.update(SELECTIOIN_CRITERIA, UPDATED_DATA)

Example

Consider the mycol collection has the following data.

{ "_id" : ObjectId(5983548781331adf45ec5), "title":"MongoDB Overview"}

{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}

{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}

Following example will set the new title 'New MongoDB Tutorial' of the documents
whosetitle is 'MongoDB Overview'.

Laboratory Practice-I/ADBMS/TE-IT Page 18


>db.mycol.update({'title':'MongoDB Overview'},{$set:{'title':'New MongoDB
Tutorial'}})
>db.mycol.find()
{ "_id" : ObjectId(5983548781331adf45ec5), "title":"New MongoDB Tutorial"}
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
>

By default, MongoDB will update only a single document. To update multiple


documents,you need to set a parameter 'multi' to true.

>db.mycol.update({'title':'MongoDB Overview'},
{$set:{'title':'New MongoDB Tutorial'}},{multi:true})

Laboratory Practice-I/ADBMS/TE-IT Page 19


Assignment No -1-C

Title:- Execute at least 10 queries on any suitable MongoDB database that


demonstrates following:

a. Find and find One (specific values)

b. Query criteria (Query conditionals, OR queries, $not, Conditional semantics) Type-


specific queries (Null, Regular expression, Querying arrays)

c. $ where queries

d. Cursors (Limit, skip, sort, advanced query options)

Theory:-

a. Find and find One (specific values)


b. find() - returns a cursor to the selected documents that matched with the
specified criteria.It is used to find particular data from the MongoDB database.
It takes 3 arguments and they are query (also known as a condition), query
projection (used for mentioning which fields to include or exclude from the
query), and the last argument is the general query options (like limit, skip,
etc).The find() method does not return null, it returns a cursor.
The find() returns all the documents from a collection if no parameter is
passed.
c. findOne() - returns a the first document that matched with the specified
criteria.It is used to find one document according to the condition. If multiple
documents match the condition, then it returns the first document satisfying
the condition

Syntax:
db.collection.findOne(query, projection)

Laboratory Practice-I/ADBMS/TE-IT Page 20


Parameters:
1. query: Optional. Specifies the criteria using query operators.
2. projection: Optional. Specifies the fields to include in a resulted document.

**********Basic Mongo db commands*****************

1. Show all available databases:

show dbs;

Select a particular database to access, e.g. mydb . This will create mydb if it does not
already exist:

use mydb;

2. Show all collections in the database (be sure to select one first, see above):

show collections;

3. To check your currently selected database, use the command db

> db
mydb

4. db.dropDatabase() command is used to drop a existing database.

db.dropDatabase()

5. db.people.insert({name: 'Tom', age: 28});


Or

db.people.save({name: 'Tom', age: 28});


The difference with save is that if the passed document contains an _id field, if a
document already exists with that _id it will be updated instead of being added as new.

Two new methods to insert documents into a collection, in MongoDB 3.2.x:-

6. Use insertOne to insert only one record:-

db.people.insertOne({name: 'Tom', age: 28});


7. Use insertMany to insert multiple records:-

db.people.insertMany([{name: 'Tom', age: 28},{name: 'John', age: 25}, {name: 'Kathy',


age: 23}])

Laboratory Practice-I/ADBMS/TE-IT Page 21


db.test.insertMany([
{name:"Any", age:"21", status:"busy"},
{name:"Tony", age:"25", status:"busy"},
{name:"Bobby", age:"28", status:"online"},
{name:"Sonny", age:"28", status:"away"},
{name:"Cher", age:"20", status:"online"}
])

8. The basic syntax of update() method is as follows:

>db.COLLECTION_NAME.update(SELECTIOIN_CRITERIA, UPDATED_DATA)
>db.mycol.update({'title':'MongoDB Overview'},{$set:{'title':'New MongoDB
Tutorial'}})

9. To list the collection:

db.test.find({})
10. To skip first 3 documents:

db.test.find({}).skip(3)
11. To sort descending by the field name:

db.test.find({}).sort({ "name" : -1})


12. to sort ascending just replace -1 with 1

db.test.find({}).sort({ "name" :1})

13. to count the results:

db.test.find({}).count()

Laboratory Practice-I/ADBMS/TE-IT Page 22


Assignment no :- 02

Aim:- Implement Map-reduce and aggregation, indexing with suitable example in


MongoDB.
Demonstre the following.

Objective: To Study of MongoDB

Theory:-

1. Map-Reduce

In very simple terms, the mapReduce command takes 2 primary inputs, the mapper function and the
reducer function. A Mapper will start off by reading a collection of data and building a Map with
only the required fields we wish to process and group them into one array based on the key.

And then this key value pair is fed into a Reducer, which will process the values. Map/Reduce is a
framework which allows to parallelize the processing of large and very large datasets across many
physical or virtual servers. A typical Map Reduce program consists of two phases .

 map phase: filter / transform / convert data


 reduce phase: perform aggregations over the data

Map: – It is a JavaScript function. It is used to map a value with a key and produces a key-value
pair.
Reduce: – It is a JavaScript function. It is used to reduce or group together all the documents
whichhave the same key.

Advantages
Scalable (due to simple design) Runs
on cheap commodity hardware
Procedural control i.e. we can control of the execution of every step

Disadvantages
1. It is not flexible i.e. the MapReduce framework is rigid.
A lot of manual coding is required, even for common operations such as join, filter, projection,
aggregates, sorting, distinct...
2. Semantics are hidden inside the map and reduce functions, so it is difficult to maintain,
extendand optimize them

Laboratory Practice-I/ADBMS/TE-IT Page 23


Syntax:-

collection_name. map-Reduce(function(Map function function (Reduce function))

Application Of MapReduce
Entertainment: To discover the most popular movies, based on what you like and what you
watched in this case Hadoop MapReduce help you out. It mainly focuses on their logs and clicks.
E-commerce: Numerous E-commerce suppliers, like Amazon, Walmart, and eBay, utilize the
MapReduce programming model to distinguish most loved items dependent on clients’ inclinations
or purchasing behavior.
It incorporates making item proposal Mechanisms for E-commerce inventories, examining website
records, buy history, user interaction logs, etc.

Data Warehouse: We can utilize MapReduce to analyze large data volumes in data warehouses
while implementing specific business logic for data insights.
Fraud Detection: Hadoop and MapReduce are utilized in monetary enterprises, including
organizations like banks, insurance providers, installment areas for misrepresentation recognition,
pattern distinguishing proof, or business metrics through transaction analysis.

2 :- Indexing

 •Indexes support the efficient execution of queries in MongoDB. Indexes support the efficient
resolution of queries. Without indexes, MongoDB must scan every document of a collection to
select those documents that match the query statement. This scan is highly inefficient and
require MongoDB to process a large volume of data.

 Indexes are special data structures, that store a small portion of the data set in an easy-to-
traverse form. The index stores the value of a specific field or set of fields, ordered by the valueof
the field as specified in the index.

Syntax
The basic syntax of createIndex() method is as follows().

Laboratory Practice-I/ADBMS/TE-IT Page 24


>db.COLLECTION_NAME.createIndex({KEY:1})

Index Display

db.collection.getIndexes()

Index Drop

db.collection.dropIndex()

3:- Aggregation

Aggregations operations process data records and return computed results.

Aggregation operations group values from multiple documents together, and can perform a
variety of operations on the grouped data
For aggregation in mongodb use aggregate() method.

MongoDB’s aggregation framework is modeled on the concept of data processing pipelines.


• Documents enter a multi-stage pipeline that transforms the documents into an
aggregatedresult.
• Other pipeline operations provide tools for grouping and sorting documents by specific
fieldor fields.
• In addition, pipeline stages can use operators for tasks such as calculating the average
orconcatenating a string.

Expression Description
 $sum Sums up the defined value from all documents in the collection.

 $avg Calculates the average of all given values from all documents in the collection.

 $min Gets the minimum of the corresponding values from all documents in the
collection.

 $max Gets the maximum of the corresponding values from all documents in
thecollection.

 $first Gets the first document from the source documents according to the grouping.

 $last Gets the last document from the source documents according

Laboratory Practice-I/ADBMS/TE-IT Page 25


MIN()

db.student.aggregate ([{$group :
{_id : "$subject",
marks : {$min : "$marks"}}}]);

SQL Equivalent Query


Select subject, min(marks) from student
group by subject

MAX()

db.student.aggregate ([{$group :
{_id : "$subject",
marks : {$max : "$marks"}}}]);

AVG()

db.student.aggregate ([{$group :
{_id : "$subject",
marks : {$avg : "$marks"}}}]);

FIRST()

db.student.aggregate ([{$group :
{_id : "$subject",
marks : {$first : "$marks"}}}]);

LAST()

db.student.aggregate ([{$group :
{_id : "$subject",
marks : {$last : "$marks"}}}]);

conclusion:Thus ,we have studied about how to use map-reduce, aggregation and indexing in
Mongodb.

Laboratory Practice-I/ADBMS/TE-IT Page 26


Assignment No:-3
Case Study: Design conceptual model using Star and Snowflake schema for any one database

Laboratory Practice-I/ADBMS/TE-IT Page 27


Assignment No:-4
Mini Project

Pre-requisite: Build the mini project based on the requirement document and design
prepared as apart of Database Management Lab in second year.
1. Form teams of around 3 to 4 people.
2. Develop the application:Build a suitable GUI by using forms and placing the controls on
it for any application. Proper data entryvalidations are expected.
Add the database connection with front end. Implement the basic CRUD operations.

Prepare and submit report to include: Title of the Project, Abstract, List the hardware and
software requirements at the backend and at the front end, Source Code , Graphical User
Interface, Conclusion.

Laboratory Practice-I/ADBMS/TE-IT Page 28

You might also like