0% found this document useful (0 votes)
43 views4 pages

Practical 4 NoSQL PARTH

The document discusses indexing, aggregation, and map reduce in NoSQL databases. It includes examples of creating different indexes in a MongoDB collection, as well as examples of aggregation operations to group and compute results from multiple documents.

Uploaded by

papatel4045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

Practical 4 NoSQL PARTH

The document discusses indexing, aggregation, and map reduce in NoSQL databases. It includes examples of creating different indexes in a MongoDB collection, as well as examples of aggregation operations to group and compute results from multiple documents.

Uploaded by

papatel4045
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

2CEIT405-NoSQL DATABASE SYSTEM 22012021038 _PARTH PATEL S.

PRACTICAL – 4
AIM: Indexing , Aggregation and Map Reduce in NoSQL-DB.

1. Indexing

 creating the Assets collection.

for( var iCounter=1;iCounter<= 80000;iCounter++){


db.Asset_038.insert({
"Name":"Voting"+iCounter,
"Desc":"Story about a college student"+iCounter,
"Rank":iCounter,
"Language":["English","Hindi","Tamil"],
"AssetGrp":[{"GrpName":"16+",
"Desc":" Can be admitted in college 16+ years old"+iCounter}]
})
}

 Default_id Index :

This is a unique Index created on the ID field of the collection. Please note that we cannot
drop this Index, as it’s the default.
db.Asset.getIndexes()

 single field Index :

Batch : 4IT-B3 Page 20


2CEIT405-NoSQL DATABASE SYSTEM 22012021038 _PARTH PATEL S.

Apart from the Default_id Index created by MongoDB, it allows us to create a user-defined
Index
db.Asset_038.createIndex( { Name : 1 } )

Compound Index :
MongoDB allows us to create a single structure to refer multiple fields.
db.Asset_038.getIndexes()

2. 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 to return a single result. In SQL count(*) and with group by is an
equivalent of mongodb aggregation

Create collection name as “gnu_038”


db.createCollection(“gnu_038”)

Add 4-5 relevant documents in same collection.


db.gnu_038.insertMany([
{
" title": "MongoDB Overvie",

Batch : 4IT-B3 Page 21


2CEIT405-NoSQL DATABASE SYSTEM 22012021038 _PARTH PATEL S.

"Description" : "MongoDB is no sql database",


by_user: "parth",
"url": "http://www.ganpatuniversity.ac.in",
tags: ['mongodb', 'database', 'NoSQL'],
likes: 264
},
{
" title": "MongoDB Overvie",
"Description" : "MongoDB is no sql database",
by_user: "psp",
"url": "http://www.ganpatuniversity.ac.in",
tags: ['mongodb', 'database', 'NoSQL'],
likes: 15
},
{
" title": "MongoDB Overvie",
"Description" : "MongoDB is no sql database",
by_user: "parth patel",
"url": "http://www.ganpatuniversity.ac.in",
tags: ['mongodb', 'database', 'NoSQL'],
likes: 159
}
])

Batch : 4IT-B3 Page 22


2CEIT405-NoSQL DATABASE SYSTEM 22012021038 _PARTH PATEL S.

Basic syntax of aggregate() method is as follows :-

Batch : 4IT-B3 Page 23

You might also like