Hong Kong Baptist University · FACULTY OF COMPUTER SCIENCE

AIDM7450 Chap.6 Relational Data and MongoDB CRUD

- one subject, every graph, every model, every mark
7 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 6 of 7 · AIDM7450

Relational Data and MongoDB CRUD

Choose a data model from the workload

A database management system centralises access, integrity, security and recovery. This chapter reviews transactions and the ACID properties before comparing relational tables, primary and foreign keys with document collections, documents and fields. MongoDB's JSON-like model supports flexible aggregates but uses different query and join assumptions.

CRUD is treated as a result-checked cycle: inserted identifiers, returned documents, matched and modified counts, and deleted counts are evidence that the intended operation reached the intended record.

Relational and document models can represent the same digital-media story while making different operations easy to express.

Tables expose relationships through keys and joins; a document can keep a frequently retrieved aggregate together through embedded fields or references. The decision follows workload and integrity needs rather than a product slogan.

Connection lifecycle is part of correctness as well: create the client from protected configuration, connect, await operations, handle errors and close the resource even when an operation fails.

In this chapter

What this chapter covers

  • 01

    DBMS access, integrity and recovery

  • 02

    Transactions and ACID properties

  • 03

    Relational tables and key relationships

  • 04

    SQL definition and manipulation roles

  • 05

    NoSQL database families

  • 06

    JSON-like document storage

  • 07

    MongoDB insert, find, update and delete results

Worked example · free

Model a digital story collection

Q [9 marks]. AskSia-authored practice. A newsroom stores stories with variable media lists and usually retrieves one complete story by slug. Compare relational and document designs. The marks shown are an AskSia study allocation.
The bridge maps comparable roles across two storage models.The bridge maps comparable roles across two storage models. Horizontal lines connect table to collection, row to document and column to field name.Translate the role, not just the wordRelationalMongoDBtablecollectionrowdocumentcolumnfield nameA mapping helps orientation; it does not make the storage models identical.
The bridge maps comparable roles across two storage models. Horizontal lines connect table to collection, row to document and column to field name.
  • 3Describe a relational story and media relationship.
  • 3Describe an embedded document aggregate.
  • 3Recommend from the stated access pattern and trade-off.
The marks shown are an original study weighting and not a university assessment scheme. A relational design can place stories and media in related tables, making cross-story constraints and joins explicit. A document design can embed the variable media list inside each story, matching the common operation that retrieves and replaces one story as a unit. The document design fits the stated workload if the team accepts weaker join support and adds validation for required fields. The recommendation follows the operation pattern rather than a universal claim.
Sia tip — Map the operation you perform most often before choosing the storage model. Product labels do not reveal the best aggregate boundary.
Glossary

Key terms

DBMS
Software that manages databases and provides controlled client access to stored data.
Transaction
A unit of work that completes as a whole or leaves the system unchanged.
Primary Key
One or more attributes that uniquely identify a record in a table.
Foreign Key
Attributes whose values reference the primary key of another table.
Document Database
A database model that stores data as self-contained documents with named fields.
CRUD
The create, read, update and delete operations used to manage stored data.
FAQ

Relational Data and MongoDB CRUD FAQ

What does atomicity protect?

Atomicity protects a multi-step transaction from being left half complete. Either all effects occur or none do. Consistency, isolation and durability protect different contracts, so naming ACID without attaching each property to a failure mode does not explain the transaction.

Does JSON make something a document database?

No. JSON is a text representation used for data exchange. A document database adds persistence, indexing, querying, access control and operational behaviour. Applications may exchange JSON without storing it, and document databases may use JSON-like structures through a driver.

Why inspect matchedCount and modifiedCount separately?

A matched document proves the filter identified a record. Zero modification may mean the requested values were already present or the update did not target the intended field. No match means the filter failed. Read the postcondition before labelling either case successful or failed.

Study strategy

Exam move

Take one application feature and sketch both a relational and document representation. Mark identity, relationships, the usual read unit and one integrity rule. Then perform one create, read, update and delete operation with neutral test data, recording the result signal and postcondition. Treat the method call as an attempt and the returned counts or document as evidence.

Attach each ACID property to a concrete failure: partial completion for atomicity, invalid state for consistency, interference between concurrent work for isolation, and lost committed work for durability. Translate table, row and column into collection, document and field only as orientation, then list one difference that prevents the mapping from becoming an equivalence claim.

For the workload comparison, write the most frequent read and update before choosing embedded or referenced data. Use a unique neutral identifier in each CRUD filter and predict the returned signal. After insertion, record the identifier; after reading, handle no result; after updating, distinguish matched from modified counts; after deletion, verify deleted count and the absent postcondition.

Close the client in a final path and repeat one operation with a forced error to prove resource cleanup does not depend on success. Keep filters narrow throughout the exercise and inspect the intended record before destructive work, so a successful method return cannot conceal an operation against the wrong document.

Working through Relational Data and MongoDB CRUD in AIDM7450? Sia is AskSia’s AI Computer Science tutor — ask any AIDM7450 Relational Data and MongoDB CRUD question and get a clear, step-by-step explanation grounded in how AIDM7450 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 16 of your subjects at Hong Kong Baptist University, plus 1,000+ more Bibles across the AskSia library.
Sia - your AIDM7450 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works