💡 Common Mistake:Embedding collapses three Oracle tables into one document ➔ great for “read the whole drone” but duplicates shared data (type/manufacturer) across drones.
🔹 Generate the JSON from Oracle
JSON_OBJECT / JSON_ARRAYAGG
SELECT JSON_OBJECT( 'drone_id' VALUE drone_id, 'type' VALUE JSON_OBJECT('code' VALUE dt_code, 'model' VALUE dt_model, 'manufacturer' VALUE manuf_name), 'RentalInfo' VALUE JSON_ARRAYAGG( JSON_OBJECT('rent_no' VALUE rent_no, 'bond' VALUE rent_bond) ORDER BY rent_no ) FORMAT JSON)FROM drone.rental NATURAL JOIN drone.drone NATURAL JOIN drone.drone_type NATURAL JOIN drone.manufacturerGROUP BY drone_id, dt_code, dt_model, manuf_name;
💡 Common Mistake:JSON_ARRAYAGG needs GROUP BY ➔ it aggregates child rows (rentals) into one array per parent (drone); non-aggregated columns must be grouped.
⚖️ Core Decision Matrix
Approach
Store
Best when
Cost
Embedded (denormalised)
nested sub-docs
always read together; rarely changes alone
duplication across parents
Reference (normalised)
ObjectId pointer
large / shared / independently updated
app must do the “join”
When It Flips: references mimic a foreign key but are not enforced by the engine — integrity is the application's responsibility, unlike Oracle's referential integrity.
🧠 Active Recall
When would you embed rental history in the drone document vs reference it in a separate collection?
Hint: Read-together + change-independently.
Answer
Short answer: Embed when the rentals are always read with the drone and rarely change alone; reference when rentals are large, shared, or updated independently of the drone.
Why:No enforced FK ➔ a reference is just a stored ObjectId; the application performs and protects the join.