ICT704 Non-Relational Database Systems: MongoDB Report

Verified

Added on  2022/10/16

|7
|1182
|336
Report
AI Summary
This report provides an overview of MongoDB, a NoSQL database system, and its application. It begins with an introduction to MongoDB, highlighting its scalability, performance, and flexible data storage capabilities, contrasting it with SQL databases. The report then delves into MongoDB's database structure, explaining how data is organized within collections using embedded documents to store related data within a single document for easy access and manipulation. It also discusses two approaches to handling relationships between documents: embedding and referencing. The report then details working with queries, including inserting data using insertOne and insert functions, and finding data using the find() method, including using specific criteria. Furthermore, it describes the use of the distinct and aggregate functions for data retrieval and calculations. The report also covers updating data using the updateOne method. Finally, the report concludes by summarizing the advantages of MongoDB and suggesting improvements, such as enhancing the way related schemas are joined using a single query.
Document Page
Table of Contents
Introduction.................................................................................................................................................2
Database structure......................................................................................................................................2
Working with queries..................................................................................................................................2
conclusion...................................................................................................................................................3
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Introduction
MongoDB is part of the NoSQL database system, and it is an open-source database system, which
provides easy scalability high performance and availability.
MongoDB provides a flexible format for storing data because it does not require its document to have
the same schema. Meaning fields in a single collection can differ from a document to document.
Database structure
MongoDB have different ways of structuring documents in a collection. Unlike SQL NoSQL allows related
data to be embedded within a single document. We have used this structure in organizing the data in a
single collection. Embedding documents allow the associated data to be accessed, retrieved and
manipulated within a single database.
We have created a single collection called the GameData. The collection contains the fields of all the
documents in an embedded structure. The structure makes it easy to insert and retrieve data.
Handling Relationship in database
MongoDB use two approaches to create relationship between documents. The first approach is
embended approach. These methods use a single collection to store data. For example, the developer
information can be stored as a collection by itself but instead of separating the files wi create an array
for developer information and embend it to the collection with game title. The approach is simple to
implement and use. The advantage of using the approach is that it requires a single query to execute a
query. Disadvantage it may become difficult to handle queries when the data size is big.
The second approach is creating a referenced relationship. Here we create different collection for each
related data. For example, we can create a collection named developer and reference the developer id
to the game collection. The advantage is that it is easy to manage the size of a document. On the other
side we will need two queries if we want torereive the developer details for a specific title.
Working with queries
The first step in creating the database was to add the provided information. Entering data was a carefull
process in order to avoid spelling mistakes and make sure data had same datatype. To method were
used in inserting data; insertOne function and insert function. The insert function allows insertion of
multiple data at once.
Syntax
Db.gameData.insert ([{ key:”values”, key2: :value” }, {key:”values”, key1:”values”}])
The above code will add two data to the collection gameData.
Finding data is an essential feature for database. Just like SQL, MongoDB has a method that allows data
to be fetched from the database. To fetch all data we used the find() method. This is how it is used.
Db.gameData.find().pretty()
Document Page
The method will return all data in a JSON format. The pretty() function returns data in an organized
format that makes it easy to read and understand data. It is even possible to find data using specific
criteria. Below code was used to return all games title whose price is zero dollars.
db.GameData.find({price:0},{title:1, _id:0}).pretty()
The first option defines the search criteria, while the second option indicates the fields to be returned.
The Id field is returned by default. To prevent it from being displayed it is defined with a value of zero(0).
Any key that needs to be returned is defined and given a value of one.
To select different values in a database we use the distinct function. The function will find duplicates
values and return them only once.
The below query select a list of title movies anf their developers
Document Page
syntax
db.GameData.distinct("developerName")
The above query will return the developers name and display them in an array format.
Aggregate is another function that wa used in querying the database. The function is mainly used in
doing calculation queries. The query below was used in counting the number of games in a collection
and return it with a label number of games.
db.GameData.aggregate({$count:"number of games"}).
The method was used to find the average price of the advisory content.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
showing title and price for game less than $4
Showing all games that were released before 2016
db.GameData.aggregate([{$group:{_id: "$contentAdvisoryRating",avgPrice: { $avg: "$price" }}}])
The above query groups the games together using the advisoryrating field. Finally, the query will return
the average price for each group.
Returning the title movie and their size in mbs
Document Page
Showing days that have passed since the game was updated
MongoDB allows new fields to be added to the to a collection or in a document within a collection. The
aggregate function is used to add new fields. Below query will add a new field to a document with the
specified id.
db.GameData.aggregate([{ $match:{_id:1207472156}}, { $addFields: { "developerCountry": "US" } }] )
Document Page
Update one method is used to update data to MongoDB. The function pick the first option to return a
field to be updated and the second set the data to update.
db.GameData.updateOne(
{ "title": "Word Warp - A Word Puzzle Game" },
{$set: { "currentVersion": "3.3.5", "currentVersionNotes": "Bug fixes and stability improvements" ,
"releaseDate":"2019-08-16T10:08:56Z", "averageUserRating":4, "userRatingCount":14}})
conclusion
MongoDB is becoming one of the most used NoSQL database systems because of its amazing features.
MongoDB is a schema-less database. It does not require any migration of the database but depends on
the code. It is also easy to scale. New fields can be added to a collection and fields can be removed from
the collection. With this and other advantages of using MongoDB, some features need to be included to
make the work of developers and easy. MongoDB lacks a proper way of joining related schemas
together. To achieve this feature you need to use two queries. One of my recommendations is for
developers to come up with a technique that can allow multiple related schemas to be joined together
by use of a single query.
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]