Assignment 2
NoSQL Database Design and Build
Lecturer: Dr Andy Wolstenholme
Module Code: CO7401
Remember to Check-In!
15 min Check-In Window
Bluetooth on
Connect to Internet
Turn on GPS/Location Services 2
Assignment 2
In this assignment you will demonstrate your knowledge and practical
skills in NoSQL databases
Learning Outcomes Assessed
LO2. Demonstrate designing, implementing, and managing non-relational
(NoSQL) databases.
LO3. Effectively apply advanced concepts in databases, showcasing expertise in
query optimisation, performance tuning, and utilising sophisticated features
during the creation and tuning process.
LO4. Critically evaluate and select appropriate database solutions based on
specific data management requirements, demonstrating an understanding of the
strengths and weaknesses of SQL and NoSQL approaches.
Assignment Review
Detailed review of the assignment in
CO7401 NoSQL Databases Design and Build - Assignment 2.pdf
Data Modelling
Databases: the logical groupings of your collections. In this assignment you’ll
just have one database
Collections: the collections of documents you will have
Fields: the data elements
Data Types: string, int, float, date, Boolean etc
Descriptions: describe the contents of the field
Data Validation: Specify any validation rules for fields (e.g. list of expected values,
email format, phone number format).
Data Quality: Define data quality standards and metrics
(e.g. completeness, accuracy, consistency).
Indexes: Document any indexes created on the collection (e.g. index on email for
efficient search).
Relationships: how are the collections related
API Reference: If the catalog is exposed through an API (application
programming interface), provide detailed API documentation. Not necessary in
the assignment.
Documentation - Data Dictionary
Collection Custome
: rs
Field Data
Name Type Description Index
_id ObjectId Unique identifier for the customer document
customerNam
e String Customer's name
membershipN
o Int Customer membership number starting at 100 Y
contact Object Customer’s contact infomation
contact.email String Customer's email address Y
Customer's phone number in the form (area code) nnn-nnnn.
contact.phone String All numbers are US based.
purchaseHisto
ry Array Array of purchased items (optional)
Data Dictionary
createdAt Date Timestamp of account creation
Best for descriptions
updatedAt Date Timestamp of last update
ObjectId – internal unique ID
Regular String, Integer, Float, Boolean columns
Nested data uses the parent object as a prefix
Arrays are clearly labelled
Documentation - UML
We can use a drawing package to create a UML
diagram
UML = Universal Modelling Language
Best for showing relationships
https://app.creately.com/d/start/dashboard
Documentation - JSON
An example makes it real // Example customer document
{
Some comments but not as "_id": "64785f32c345678901234567",
descriptive as a data "name": "John Doe",
"membershipNumber": 321,
dictionary "contact":{
"email": "johndoe@example.com",
Quick and easy for short "phone": "(123) 456-7890"
documents }
"purchaseHistory": [
0: "Bread",
1: "Milk",
2: "Pizza"
],
"createdAt": "2024-04-12T12:34:56Z",
"updatedAt": "2024-04-13T15:23:10Z"
}
Create Your Schema Objects
MongoDB Objects to create
Database
Collections
Documents
Indexes
Queries
Aggregations
Recommend that you create them as part of your Python script,
however you could create the Database and Collections manually
Creating your Data
Options:
Create Data
1. Enter data in a spreadsheet and save as csv
2. Create random data in Python dictionary and save to a JSON file
Load into MongoDB
1. Use the Add Data option at the Collection level to import CSV or JSON
2. Type into MongoDB using the “Insert Document” option – not advised!
Combined
1. Create random data in Python and push to the Collection
Example Python
Remember how we created and inserted our recipes
Python Random Data Example
Random from a list of values
Random integer
Random floating point
Weighted random choice
Example code
{'Food': 'Fries', 'quantity': 1, 'Drink': 'Water', 'Price':
Assignment Workshop
For the remainder of this session you will start work on your
assignment
Thank You
Any questions?