You are on page 1of 13

Academic Assessment

Module Assessment Type


Year Number

A19 Database Design and Pattern(ADipIT03) A2 Individual Report

[MongoDB]

Student Id : [NP03S180037]
Student Name : [Ashish – Parajuli]
Section : [ADC6]
Module Leader : [Jnaneshwar Bohara]
Lecturer : [Mr. Hemanga Gautam]
Submitted on : <15-02-2020>
Acknowledgement

First of all, I would like to thank my Lecturer Mr. Hemanga Gautam and Mr. Sachin kafle
for making me able to complete this project with success. I would like to thank my
friends and teachers who helped me with their valuable suggestion and guidance has
been helpful in various phases id the completion of the project.
Contents
Mongo dB Task Codes ---------------------------------------------------- 1
1: Import the data into your own MongoDB database 1
1.1 Show the command to do this 1
1.2 Write a command to show how many documents are in
your collection 1
2: Analyse the data 2
2.1 Show one document 2
2.1 Show the unique values in one field 3
2.3 Shows a set of documents based on some criteria. Output
just two fields from the document. 4
2.4 Use a regular expression to search for some criteria. The
search should be case insensitive 5
3: Reshape the collection 6
3.1 Update a field within the collection 6
3.2 Create a new collection based on a subset of the dataset.
Include a query to show a document from the new collection 9
Advantage and Disadvantage of Mongodb ----------------------- 10
1: Advantage 10
2. Disadvantage 10
Mongo dB Task Codes

1: Import the data into your own MongoDB database


1.1 Show the command to do this

Code:- mongoimport --db coursework --collection twitter –file katpost.json

1.2 Write a command to show how many documents are in your collection

Code:- db.twitter.count()

1 |Page
2: Analyse the data
2.1 Show one document

Code:- db.twitter.find().limit(1).pretty()

2 |Page
2.1 Show the unique values in one field

Code:- db.twitter.distinct('text')

3 |Page
2.3 Shows a set of documents based on some criteria. Output just two fields from the
document.

Code:-
db.twitter.find({"id_str":"1088965783777173506"},{"_id":0,"id_str":1,"text":1}).pret
ty();

4 |Page
2.4 Use a regular expression to search for some criteria. The search should be case
insensitive

Code:- db.twitter.find({"user.location" : { $regex: /^KA/i }},{"user.location" : 1 ," text"


: 1 , "_id" : 1 });

5 |Page
3: Reshape the collection
3.1 Update a field within the collection

BEFORE UPDATE

Code:-
db.twitter.update({ "_id" : ObjectId("5c5d6988be9a1c0096797d8a") },{ $set:{text:
"Updated File",}})

6 |Page
AFTER UPDATE

7 |Page
8 |Page
3.2 Create a new collection based on a subset of the dataset. Include a query to show a
document from the new collection

Code:-

db.twitter.find({"text" : "Updated File"}).count()

> db.twitter.aggregate( [{$match: {"text" : "Updated File"}}, {$out:


"updatedcollection"} ] )

> db.updatedcollection.find({"text" : "Updated File"}).count()


1

> db.updatedcollection.find().pretty()Figure 1 Screenshot: Showing one record from


new collection

9 |Page
Advantage and Disadvantage of Mongodb

1: Advantage
The advantages of using mongo dB for data handling are as follows:- (point, tutorials, 2020)
(studytonight)
1. Flexible Database
As we know that MongoDB is a schema-less database. That means MongoDB is a
database of documents containing different documents in one collection. The number of
fields, the content and the document size may varies from one document to another. This
thing gives us versatility and freedom to store different types of data.

Unlike SQL databases, where you need to decide and designate the schema of a table
before importing data, MongoDB collections do not, by default, allow its documents to
have the same scheme. that is: -

 Records in a single collection do not need to have the same set of fields, and the data
type for a field may vary from document to document within a collection.
 To modify the document structure in a collection such as creating new fields, dropping
existing fields, or modifying the field values to a new type, upgrade the documents to the
new structure.
Such versatility makes record mapping easier to an entity or an object. Each document
can suit the data fields of the entity represented, even if the document differs substantially
from other documents in the collection.

2. It uses internal memory for storing the working set, enabling faster access of data.
3. It is not needed to converse/map the application objects to the database objects.
4. MongoDB supports dynamic database query using a document query language which is
almost as effective as SQL.

2. Disadvantage
The disadvantages of using mongo dB for data handling are as follows:- (Data flair, 2018)
1. High Memory usage
MongoDB stores key names for every pair of values. There's also data redundancy due
to no functionality of join. Which results in inclining unnecessary excessive memory usage.

2. Limited Nesting: Like You cannot perform nesting of documents for more than 100 levels.
3. MongoDB doesn’t support joins like a (RDBMS)Relational Database Management
System.
4. It provides limited data size, not more than 16MB

10 | P a g e

You might also like