model
the real world using data structuresmodel
the real world using data structuresmodel
ed and stored using general-purpose data models (e.g., JSON, XML, CSV, etc.)model
the real world using data structuresmodel
ed and stored using general-purpose data models (e.g., JSON, XML, CSV, etc.)model
the real world using data structuresmodel
ed and stored using general-purpose data models (e.g., JSON, XML, CSV, etc.)relations
or tables
tuples
id | name | age |
---|---|---|
1 | Tarik | 21 |
2 | Miguel | 5 |
3 | Ethan | 69 |
id | name | age |
---|---|---|
1 | Tarik | 21 |
2 | Miguel | 5 |
3 | Ethan | 69 |
friend1 | friend2 |
---|---|
1 | 2 |
1 | 3 |
2 | 3 |
SELECT name FROM people WHERE id IN (SELECT friend2 FROM friends WHERE friend1 = 3 or friend2 = 3));
id | name | location |
---|---|---|
1 | Ethan | New York |
id | job_id | job_title |
---|---|---|
1 | 1 | Software Engineer at Hootsuite |
1 | 2 | Software Engineer at PDT |
1 | 3 | Floor mopper at The Miguel Company |
{ "id": 1, "name": "Ethan", "jobs": [ { "id": 1, "title": "Software Engineer at Hootsuite" }, { "id": 2, "title": "Software Engineer at PDT" }, { "id": 3, "title": "Floor mopper at The Miguel Company" } ], "location": "New York"}
id | name | location |
---|---|---|
1 | Ethan | New York |
2 | Miguel | New York |
What if The city of New York was renamed?
id | name | location |
---|---|---|
1 | Ethan | 314141414 |
2 | Miguel | 314141414 |
location_id | location_name |
---|---|
314141414 | Goblins |
People | Locations |
---|---|
|
|
// Joins the people table with the locations table// to find out where Ethan and Miguel livedb.people.find({ $or: [ { id: 1 }, { id: 2 } ]}, { _id: 0, name: 1, location: 1}).forEach(function(person) { db.locations.findOne({ location_id: person.location }, { _id: 0, location_name: 1 }, function(location) { console.log(person.name + " lives in " + location.location_name); });});
$ node index.jsEthan lives in GoblinsMiguel lives in Goblins
schema-on-read
:schema-on-write
:--- Migrate the people table to have a first and last name--- Then move the split the old name column into first and last name columnsALTER TABLE peopleADD COLUMN first_name VARCHAR(255)ADD COLUMN last_name VARCHAR(255);--- Split the name column into first and last name columnsUPDATE peopleSET first_name = SUBSTRING(name, 1, LOCATE(' ', name) - 1),last_name = SUBSTRING(name, LOCATE(' ', name) + 1);--- Drop the old name columnALTER TABLE peopleDROP COLUMN name;
// If the user doesn't have a `first_name` or `last_name` field,// then we can add them by splitting the `name` fieldif (!person.first_name || !person.last_name) { person.first_name = person.name.split(' ')[0]; person.last_name = person.name.split(' ')[1];}// Then we can assume the user has a `first_name` and `last_name` field...
JSON
and XML
--- We join the location table to get the people--- who live in the GoblinsSELECT people.first_nameFROM peopleJOIN locationsON people.location = locations.location_idWHERE locations.location_name = 'Goblins';
// we have to look at the people array and// location array to get the people that live in Goblinsconst result = [];for (const person of people) { for (const location of locations) { if (person.location === location.location_id && location.location_name === 'Goblins') { result.push(person.first_name); } }}
// MongoDB mapReduce example// to emit the number of people in each locationconst res = db.people.mapReduce( // The map function function() { emit(this.location, 1); }, // The reduce function function(key, values) { return Array.sum(values); }, { out: 'people_by_location' });// output the resultsres.find().forEach(function(doc) { const location = db.locations.findOne({ location_id: doc.key }); console.log(doc.value + " people live in " + location.location_name);});
$ node index.js2 people live in Goblins
// dgraph query to get the people and their locations (Looks like GraphQL!)const query = `query { people(func: has(location)) { name location { location_name } }}`;const res = await dgraph.newTxn().query(query);console.log(res);
$ node index.js{ "people": [ { "name": "Ethan", "location": { "location_name": "Goblins" } }, { "name": "Miguel", "location": { "location_name": "Goblins" } } ]}
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |