slides01-15-30
slides01-15-30
JSON BSON
{
"name": "Max", MongoDB
Binary Data
"age": 29 Drivers
}
Efficient Storage
CRUD Operations & MongoDB
User
<Code>
Read
Create, Read, Update, Delete Create, Read, Update, Delete
MongoDB Server
Collection A Collection B
{ … }, { … } { … }, { … }
CRUD Operations
Create Update
insertOne(data, options) updateOne(filter, data, options)
Read Delete
find(filter, options) deleteOne(filter, options)
Flight
Schedule
Create Delete Cancel Flight
(Add) a Flight
{
"departureAirport": "MUC",
Update Display Flight
Update "arrivalAirport": "SFO", Read
Information Information
"aircraft": "Airbus A380",
"distance": 12000,
"intercontinental": true
},
{ … }
Unique IDs
Up to 100 Levels
of Nesting
Max. 16mb /
document
Documents
Arrays
Embedded
Array of
find()
[ { … }, { … }, … ] Cursor Object
In Database
{
"_id": "...",
"name": "Max",
"age": 29,
"job": "instructor"
}
Projection
In Application
{
"name": "Max",
"age": 29
}
update() vs updateOne() vs updateMany()
Use $set to patch values Use $set to patch values Use $set to patch values
Use these!
Example #2: Patient Data
Patient
{
"firstName": "Max",
"lastName": "Schwarzmueller",
"age": 29,
"history": [
{ "disease": "cold", "treatment": … },
{ … }
]
}
Tasks
2 Update patient data of 1 patient with new age, name and history entry
3 Find all patients who are older than 30 (or a value of your choice)
Modelling Relations
Schema Validation