🤩
🤩
{
}
{
field: value,
field: value,
field: value
}
1 Leslie Yepp 8125552344 Pawnee
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee"
}
1 Leslie Yepp 8125552344 Pawnee
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee"
}
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ]
}
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ]
}
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
],
"jobHistory": [
{
"title": "Deputy Director",
"yearStarted": 2004
},
{
"title": "City Councillor",
"yearStarted": 2012
},
{
"title": "Director, National Parks
Service, Midwest Branch",
"yearStarted": 2014
}
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
],
"jobHistory": [
{
"title": "Deputy Director",
"yearStarted": 2004
},
{
"title": "City Councillor",
"yearStarted": 2012
},
{
"title": "Director, National Parks
Service, Midwest Branch",
"yearStarted": 2014
}
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
],
"jobHistory": [
{
"title": "Deputy Director",
"yearStarted": 2004
},
{
"title": "City Councillor",
"yearStarted": 2012
},
{
"title": "Director, National Parks
Service, Midwest Branch",
"yearStarted": 2014
}
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
2 Ron Swandaughter 8125559347 Pawnee NULL NULL
10 1 scrapbooking
11 1 eating waffles
12 1 working
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
{
"_id": 2,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": "8125559347",
"city": "Pawnee"
}
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
2 Ron Swandaughter 8125559347 Pawnee NULL NULL
{
"_id": 2,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": "8125559347",
"city": "Pawnee"
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
2 Ron Swandaughter 8125559347 Pawnee NULL NULL
{
"_id": 2,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": "8125559347",
"city": "Pawnee",
"hobbies": [
"woodworking",
"fishing"
],
"jobHistory": [
{
"title": "Director",
"yearStarted": 2002
},
{
"title": "CEO, Kinda Good Building
Company",
"yearStarted": 2014
}
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
2 Ron Swandaughter 8125559347 Pawnee NULL NULL
{
"_id": 2,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": "8125559347",
"city": "Pawnee",
"hobbies": [
"woodworking",
"fishing"
],
"jobHistory": [
{
"title": "Director",
"yearStarted": 2002
},
{
"title": "CEO, Kinda Good Building
Company",
"yearStarted": 2014
}
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
2 Ron Swandaughter 8125559347 Pawnee NULL NULL
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
15 3 soccer
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
2 Ron Swandaughter 8125559347 Pawnee NULL NULL
3 Lauren Burhug NULL Pawnee NULL NULL
{
"_id": 2,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": "8125559347",
"city": "Pawnee",
"hobbies": [
"woodworking",
"fishing"
],
"jobHistory": [
{
"title": "Director",
"yearStarted": 2002
},
{
"title": "CEO, Kinda Good Building
Company",
"yearStarted": 2014
}
]
}
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
15 3 soccer
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
2 Ron Swandaughter 8125559347 Pawnee NULL NULL
3 Lauren Burhug NULL Pawnee NULL NULL
{
"_id": 3,
"first_name": "Lauren",
"last_name": "Burhug",
"city": "Pawnee",
"hobbies": [ "soccer" ]
}
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
15 3 soccer
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
2 Ron Swandaughter 8125559347 Pawnee NULL NULL
3 Lauren Burhug NULL Pawnee NULL NULL
{
"_id": 3,
"first_name": "Lauren",
"last_name": "Burhug",
"city": "Pawnee",
"hobbies": [ "soccer" ]
}
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
15 3 soccer
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 NULL
2 Ron Swandaughter 8125559347 Pawnee NULL NULL NULL
3 Lauren Burhug NULL Pawnee NULL NULL Pawnee
Elementary
{
"_id": 3,
"first_name": "Lauren",
"last_name": "Burhug",
"city": "Pawnee",
"hobbies": [ "soccer" ]
}
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
15 3 soccer
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 NULL
2 Ron Swandaughter 8125559347 Pawnee NULL NULL NULL
3 Lauren Burhug NULL Pawnee NULL NULL Pawnee
Elementary
{
"_id": 3,
"first_name": "Lauren",
"last_name": "Burhug",
"city": "Pawnee",
"hobbies": [ "soccer" ]
}
20 1 Deputy Directory 2004
21 1 City Councilor 2012
22 1 Director, National
Parks Service,
Midwest Branch
2014
23 2 Director 2002
24 2 CEO, Kinda Good
Building Company
2014
10 1 scrapbooking
11 1 eating waffles
12 1 working
13 2 woodworking
14 2 fishing
15 3 soccer
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 NULL
2 Ron Swandaughter 8125559347 Pawnee NULL NULL NULL
3 Lauren Burhug NULL Pawnee NULL NULL Pawnee
Elementary
{
"_id": 3,
"first_name": "Lauren",
"last_name": "Burhug",
"city": "Pawnee",
"hobbies": [ "soccer" ],
"school": "Pawnee Elementary"
}
1 b ...
2 ... ...
3 ... ...
{
...
a: “b”
...
}
1 b ...
2 ... ...
3 ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
{
...
a: “b”
...
}
1 b ...
2 c ...
3 ... ...
{
...
a: “b”
...
}
{
...
a: “c”
...
}
... ... ...
... ... ...
... ... ...
{
...
} {
...
} {
...
}
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
{
...
}
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
{
...
}
{
...
}
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
{
...
}
{
...
}
... ... ...
... ... ...
... ... ...
{
...
} {
...
} {
...
}
1 b ...
2 ... ...
3 ... ...
4 e ...
... ... ...
... ... ...
{
...
a: “b”,
...
c: {
d: “e”
...
},
...
}
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
{
...
}
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
{
...
}
{
...
}
1 b ...
2 ... ...
3 ... ...
{
...
a: “b”,
...
c: {
d: “e”
...
},
...
}
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
{
first_name:
“Lauren”,
…
}
ALTER TABLE
`CityHall`.`Users`
ADD COLUMN `school`
VARCHAR(45) NULL
AFTER `longitude`;
{
first_name:
“Lauren”,
School:
“Pawnee
Elementary”,
…
}
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632,
39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
]
}
10 1 scrapbooking
11 1 eating waffles
12 1 working
1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
import mysql.connector
# CONNECT TO THE DB
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="rootroot",
database="CityHall" )
mycursor = mydb.cursor(dictionary=True)
# THE ID OF THE USER WHOSE PROFILE WE
# WILL BE RETRIEVING AND UPDATING
userId = 1
import pymongo
from pymongo import MongoClient
# CONNECT TO THE DB
client = MongoClient()
client = pymongo
.MongoClient("mongodb+srv://root:rootroot@m
ycluster.mongodb.net/test?retryWrites=true&
w=majority")
db = client.CityHall
# THE ID OF THE USER WHOSE PROFILE WE
# WILL BE RETRIEVING AND UPDATING
userId = 1
sql = "SELECT * FROM Users LEFT JOIN
Hobbies ON Users.ID = Hobbies.user_id WHERE
Users.id=%s"
values = (userId,)
my cursor.execute(sql, values)
user = mycursor.fetchone()
user = db['Users’]
.find_one({"_id": userId})
hobbies = []
if (user["hobby"]):
hobbies.append(user["hobby"])
del user["hobby"]
del user["ID"]
for result in mycursor:
hobbies.append(result["hobby"])
user["hobbies"] = hobbies
{
'city': 'Pawnee',
'first_name': 'Leslie',
'last_name': 'Yepp',
'school': None,
'cell': '8125552344',
'latitude': 39.1703,
'longitude': -86.5366,3
'hobbies’: [
'scrapbooking’,
'eating waffles’,
'working’
],
'user_id': 1
}
{
'city': 'Pawnee',
'first_name’: 'Leslie',
'last_name': 'Yepp',
'cell': '8125552344',
'location': [-86.536632, 39.170344],
'hobbies’: [
'scrapbooking’,
'eating waffles’,
'working’
],
'_id': 1
}
user.update( {
"city": "Washington, DC",
"latitude": 38.897760,
"longitude": -77.036809,
"hobbies": [
"scrapbooking",
"eating waffles",
"signing bills"]
} )
user.update( {
"city": "Washington, DC",
"location": [-77.036809, 38.897760],
"hobbies": [
"scrapbooking",
"eating waffles",
"signing bills"]
} )
sql = "UPDATE Users SET first_name=%s,
last_name=%s, cell=%s, city=%s,
latitude=%s, longitude=%s, school=%s WHERE
(ID=%s)"
values = (user["first_name"],
user["last_name"], user["cell"],
user["city"], user["latitude"],
user["longitude"], user["school"], userId)
mycursor.execute(sql, values)
mydb.commit()
result = db['Users’]
.update_one(
{"_id": userId},
{"$set": user})
sql = "DELETE FROM Hobbies WHERE
user_id=%s"
values = (userId,)
mycursor.execute(sql, values)
mydb.commit()
if(len(user["hobbies"]) > 0):
sql = "INSERT INTO Hobbies
(user_id, hobby) VALUES (%s, %s)"
values = []
for hobby in user["hobbies"]:
values.append((userId, hobby))
mycursor.executemany(sql,values)
mydb.commit()
27 lines of code 2 lines of code
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632, 39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
],
"jobHistory": [
{
"title": "Deputy Director",
"yearStarted": 2004
},
{
"title": "City Councillor",
"yearStarted": 2012
},
{
"title": "Director, National Parks
Service, Midwest Branch",
"yearStarted": 2014
}
]
}
{
"_id": 1,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": ”8125559347",
"city": "Pawnee",
"hobbies": [
”woodworking",
”fishing"
],
"jobHistory": [
{
"title": "Director",
"yearStarted": 2002
},
{
"title": ”CEO, Kinda Good
Building Company",
"yearStarted": 2014
}
]
}
{
"_id": 3,
"first_name": "Lauren",
"last_name": "Burhug",
"city": "Pawnee",
"hobbies": [ "soccer" ],
"school": "Pawnee Elementary"
}
{
"_id": 3,
"first_name": "Lauren",
"last_name": "Burhug",
"city": "Pawnee",
"hobbies": ["soccer"],
"school": "Pawnee Elementary",
"followers": [
"Brandon",
"Wesley",
"Ciara",
...
]
}
{
"_id": 2.1,
"followers": [
"Jerry",
"Ann",
"Ben"
...
],
"is_overflow": true
}
{
"_id": 2,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": "8125559347",
"city": "Pawnee",
"hobbies": [
"woodworking",
"fishing"],
"jobHistory": [
{
"title": "Director",
"yearStarted": 2002
},
...
],
"followers": [
"Leslie",
"Donna",
"Tom" ... ],
}
{
"_id": 2,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": "8125559347",
"city": "Pawnee",
"hobbies": [
"woodworking",
"fishing"],
"jobHistory": [
{
"title": "Director",
"yearStarted": 2002
},
...
],
"followers": [
"Leslie",
"Donna",
"Tom" ... ],
"has_extras": true
}
{
a: “b”,
c: {
d: “e”
...
},
f: [“g”, “h”, “i”],
j: [
{
k: “l”
},
{
m: “n”
}
]
}
{
a: “b”,
c: {
d: “e”
...
},
f: [“g”, “h”, “i”],
j: [
{
k: “l”
},
{
m: “n”
}
]
}
{
a: “b”,
c: {
d: “e”
...
},
f: [“g”, “h”, “i”],
j: [
{
k: “l”
},
{
m: “n”
}
]
}
{
a: “b”,
c: {
d: “e”
...
},
f: [“g”, “h”, “i”],
j: [
{
k: “l”
},
{
m: “n”
}
]
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
a: “b”,
...
c: {
d: “e”
...
},
...
}
{
first_name:
“Lauren”,
…
}
{
first_name:
“Lauren”,
School:
“Pawnee
Elementary”,
…
}
{
"_id": 1,
"first_name": "Leslie",
"last_name": "Yepp",
"cell": "8125552344",
"city": "Pawnee",
"location": [ -86.536632, 39.170344 ],
"hobbies": [
"scrapbooking",
"eating waffles",
"working”
],
"jobHistory": [
{
"title": "Deputy Director",
"yearStarted": 2004
},
{
"title": "City Councillor",
"yearStarted": 2012
},
{
"title": "Director, National Parks
Service, Midwest Branch",
"yearStarted": 2014
}
]
}
{
"_id": 1,
"first_name": "Ron",
"last_name": "Swandaughter",
"cell": ”8125559347",
"city": "Pawnee",
"hobbies": [
”woodworking",
”fishing"
],
"jobHistory": [
{
"title": "Director",
"yearStarted": 2002
},
{
"title": ”CEO, Kinda Good
Building Company",
"yearStarted": 2014
}
]
}
{
"_id": 3,
"first_name": "Lauren",
"last_name": "Burhug",
"city": "Pawnee",
"hobbies": [ "soccer" ],
"school": "Pawnee Elementary"
}
{
a: “b”,
c: {
d: “e”
...
},
f: [“g”, “h”, “i”],
j: [
{
k: “l”
},
{
m: “n”
}
]
}
{
...
}
{
...
} {
...
}
{
...
}
{
...
} {
...
} {
...
}
NoSQL for Startups
NoSQL for Startups
NoSQL for Startups
NoSQL for Startups
NoSQL for Startups
NoSQL for Startups
NoSQL for Startups

NoSQL for Startups

  • 1.
  • 9.
  • 17.
  • 18.
  • 21.
    1 Leslie Yepp8125552344 Pawnee
  • 22.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee" } 1 Leslie Yepp 8125552344 Pawnee
  • 23.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee" } 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 24.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ] } 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 25.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ] } 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 26.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 27.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 28.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 29.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 30.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 31.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ], "jobHistory": [ { "title": "Deputy Director", "yearStarted": 2004 }, { "title": "City Councillor", "yearStarted": 2012 }, { "title": "Director, National Parks Service, Midwest Branch", "yearStarted": 2014 } ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 32.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ], "jobHistory": [ { "title": "Deputy Director", "yearStarted": 2004 }, { "title": "City Councillor", "yearStarted": 2012 }, { "title": "Director, National Parks Service, Midwest Branch", "yearStarted": 2014 } ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 33.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ], "jobHistory": [ { "title": "Deputy Director", "yearStarted": 2004 }, { "title": "City Councillor", "yearStarted": 2012 }, { "title": "Director, National Parks Service, Midwest Branch", "yearStarted": 2014 } ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 2 Ron Swandaughter 8125559347 Pawnee NULL NULL
  • 34.
    10 1 scrapbooking 111 eating waffles 12 1 working 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 { "_id": 2, "first_name": "Ron", "last_name": "Swandaughter", "cell": "8125559347", "city": "Pawnee" } 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 2 Ron Swandaughter 8125559347 Pawnee NULL NULL
  • 35.
    { "_id": 2, "first_name": "Ron", "last_name":"Swandaughter", "cell": "8125559347", "city": "Pawnee" } 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 2 Ron Swandaughter 8125559347 Pawnee NULL NULL
  • 36.
    { "_id": 2, "first_name": "Ron", "last_name":"Swandaughter", "cell": "8125559347", "city": "Pawnee", "hobbies": [ "woodworking", "fishing" ], "jobHistory": [ { "title": "Director", "yearStarted": 2002 }, { "title": "CEO, Kinda Good Building Company", "yearStarted": 2014 } ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 2 Ron Swandaughter 8125559347 Pawnee NULL NULL
  • 37.
    { "_id": 2, "first_name": "Ron", "last_name":"Swandaughter", "cell": "8125559347", "city": "Pawnee", "hobbies": [ "woodworking", "fishing" ], "jobHistory": [ { "title": "Director", "yearStarted": 2002 }, { "title": "CEO, Kinda Good Building Company", "yearStarted": 2014 } ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 20 1 Deputy Directory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 2 Ron Swandaughter 8125559347 Pawnee NULL NULL
  • 38.
    20 1 DeputyDirectory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 15 3 soccer 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 2 Ron Swandaughter 8125559347 Pawnee NULL NULL 3 Lauren Burhug NULL Pawnee NULL NULL { "_id": 2, "first_name": "Ron", "last_name": "Swandaughter", "cell": "8125559347", "city": "Pawnee", "hobbies": [ "woodworking", "fishing" ], "jobHistory": [ { "title": "Director", "yearStarted": 2002 }, { "title": "CEO, Kinda Good Building Company", "yearStarted": 2014 } ] }
  • 39.
    20 1 DeputyDirectory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 15 3 soccer 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 2 Ron Swandaughter 8125559347 Pawnee NULL NULL 3 Lauren Burhug NULL Pawnee NULL NULL { "_id": 3, "first_name": "Lauren", "last_name": "Burhug", "city": "Pawnee", "hobbies": [ "soccer" ] }
  • 40.
    20 1 DeputyDirectory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 15 3 soccer 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 2 Ron Swandaughter 8125559347 Pawnee NULL NULL 3 Lauren Burhug NULL Pawnee NULL NULL { "_id": 3, "first_name": "Lauren", "last_name": "Burhug", "city": "Pawnee", "hobbies": [ "soccer" ] }
  • 42.
    20 1 DeputyDirectory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 15 3 soccer 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 NULL 2 Ron Swandaughter 8125559347 Pawnee NULL NULL NULL 3 Lauren Burhug NULL Pawnee NULL NULL Pawnee Elementary { "_id": 3, "first_name": "Lauren", "last_name": "Burhug", "city": "Pawnee", "hobbies": [ "soccer" ] }
  • 43.
    20 1 DeputyDirectory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 15 3 soccer 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 NULL 2 Ron Swandaughter 8125559347 Pawnee NULL NULL NULL 3 Lauren Burhug NULL Pawnee NULL NULL Pawnee Elementary { "_id": 3, "first_name": "Lauren", "last_name": "Burhug", "city": "Pawnee", "hobbies": [ "soccer" ] }
  • 44.
    20 1 DeputyDirectory 2004 21 1 City Councilor 2012 22 1 Director, National Parks Service, Midwest Branch 2014 23 2 Director 2002 24 2 CEO, Kinda Good Building Company 2014 10 1 scrapbooking 11 1 eating waffles 12 1 working 13 2 woodworking 14 2 fishing 15 3 soccer 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632 NULL 2 Ron Swandaughter 8125559347 Pawnee NULL NULL NULL 3 Lauren Burhug NULL Pawnee NULL NULL Pawnee Elementary { "_id": 3, "first_name": "Lauren", "last_name": "Burhug", "city": "Pawnee", "hobbies": [ "soccer" ], "school": "Pawnee Elementary" }
  • 49.
    1 b ... 2... ... 3 ... ... { ... a: “b” ... }
  • 50.
    1 b ... 2... ... 3 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... { ... a: “b” ... }
  • 51.
    1 b ... 2c ... 3 ... ... { ... a: “b” ... } { ... a: “c” ... }
  • 52.
    ... ... ... ...... ... ... ... ... { ... } { ... } { ... }
  • 53.
    ... ... ... ...... ... ... ... ... { ... } { ... } { ... } ... ... ... ... ... ... ... ... ... { ... } { ... } { ... } { ... }
  • 54.
    ... ... ... ...... ... ... ... ... { ... } { ... } { ... } { ... }
  • 55.
    ... ... ... ...... ... ... ... ... { ... } { ... } { ... }
  • 56.
    1 b ... 2... ... 3 ... ... 4 e ... ... ... ... ... ... ... { ... a: “b”, ... c: { d: “e” ... }, ... }
  • 57.
    ... ... ... ...... ... ... ... ... { ... } { ... } { ... } ... ... ... ... ... ... ... ... ... { ... } { ... } { ... } { ... }
  • 63.
    1 b ... 2... ... 3 ... ... { ... a: “b”, ... c: { d: “e” ... }, ... } ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  • 64.
    { first_name: “Lauren”, … } ALTER TABLE `CityHall`.`Users` ADD COLUMN`school` VARCHAR(45) NULL AFTER `longitude`; { first_name: “Lauren”, School: “Pawnee Elementary”, … }
  • 66.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ] } 10 1 scrapbooking 11 1 eating waffles 12 1 working 1 Leslie Yepp 8125552344 Pawnee 39.170344 -86.536632
  • 67.
    import mysql.connector # CONNECTTO THE DB mydb = mysql.connector.connect( host="localhost", user="root", passwd="rootroot", database="CityHall" ) mycursor = mydb.cursor(dictionary=True) # THE ID OF THE USER WHOSE PROFILE WE # WILL BE RETRIEVING AND UPDATING userId = 1 import pymongo from pymongo import MongoClient # CONNECT TO THE DB client = MongoClient() client = pymongo .MongoClient("mongodb+srv://root:rootroot@m ycluster.mongodb.net/test?retryWrites=true& w=majority") db = client.CityHall # THE ID OF THE USER WHOSE PROFILE WE # WILL BE RETRIEVING AND UPDATING userId = 1
  • 68.
    sql = "SELECT* FROM Users LEFT JOIN Hobbies ON Users.ID = Hobbies.user_id WHERE Users.id=%s" values = (userId,) my cursor.execute(sql, values) user = mycursor.fetchone() user = db['Users’] .find_one({"_id": userId}) hobbies = [] if (user["hobby"]): hobbies.append(user["hobby"]) del user["hobby"] del user["ID"] for result in mycursor: hobbies.append(result["hobby"]) user["hobbies"] = hobbies
  • 69.
    { 'city': 'Pawnee', 'first_name': 'Leslie', 'last_name':'Yepp', 'school': None, 'cell': '8125552344', 'latitude': 39.1703, 'longitude': -86.5366,3 'hobbies’: [ 'scrapbooking’, 'eating waffles’, 'working’ ], 'user_id': 1 } { 'city': 'Pawnee', 'first_name’: 'Leslie', 'last_name': 'Yepp', 'cell': '8125552344', 'location': [-86.536632, 39.170344], 'hobbies’: [ 'scrapbooking’, 'eating waffles’, 'working’ ], '_id': 1 }
  • 70.
    user.update( { "city": "Washington,DC", "latitude": 38.897760, "longitude": -77.036809, "hobbies": [ "scrapbooking", "eating waffles", "signing bills"] } ) user.update( { "city": "Washington, DC", "location": [-77.036809, 38.897760], "hobbies": [ "scrapbooking", "eating waffles", "signing bills"] } )
  • 71.
    sql = "UPDATEUsers SET first_name=%s, last_name=%s, cell=%s, city=%s, latitude=%s, longitude=%s, school=%s WHERE (ID=%s)" values = (user["first_name"], user["last_name"], user["cell"], user["city"], user["latitude"], user["longitude"], user["school"], userId) mycursor.execute(sql, values) mydb.commit() result = db['Users’] .update_one( {"_id": userId}, {"$set": user}) sql = "DELETE FROM Hobbies WHERE user_id=%s" values = (userId,) mycursor.execute(sql, values) mydb.commit() if(len(user["hobbies"]) > 0): sql = "INSERT INTO Hobbies (user_id, hobby) VALUES (%s, %s)" values = [] for hobby in user["hobbies"]: values.append((userId, hobby)) mycursor.executemany(sql,values) mydb.commit()
  • 72.
    27 lines ofcode 2 lines of code
  • 78.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ], "jobHistory": [ { "title": "Deputy Director", "yearStarted": 2004 }, { "title": "City Councillor", "yearStarted": 2012 }, { "title": "Director, National Parks Service, Midwest Branch", "yearStarted": 2014 } ] } { "_id": 1, "first_name": "Ron", "last_name": "Swandaughter", "cell": ”8125559347", "city": "Pawnee", "hobbies": [ ”woodworking", ”fishing" ], "jobHistory": [ { "title": "Director", "yearStarted": 2002 }, { "title": ”CEO, Kinda Good Building Company", "yearStarted": 2014 } ] } { "_id": 3, "first_name": "Lauren", "last_name": "Burhug", "city": "Pawnee", "hobbies": [ "soccer" ], "school": "Pawnee Elementary" }
  • 79.
    { "_id": 3, "first_name": "Lauren", "last_name":"Burhug", "city": "Pawnee", "hobbies": ["soccer"], "school": "Pawnee Elementary", "followers": [ "Brandon", "Wesley", "Ciara", ... ] } { "_id": 2.1, "followers": [ "Jerry", "Ann", "Ben" ... ], "is_overflow": true } { "_id": 2, "first_name": "Ron", "last_name": "Swandaughter", "cell": "8125559347", "city": "Pawnee", "hobbies": [ "woodworking", "fishing"], "jobHistory": [ { "title": "Director", "yearStarted": 2002 }, ... ], "followers": [ "Leslie", "Donna", "Tom" ... ], } { "_id": 2, "first_name": "Ron", "last_name": "Swandaughter", "cell": "8125559347", "city": "Pawnee", "hobbies": [ "woodworking", "fishing"], "jobHistory": [ { "title": "Director", "yearStarted": 2002 }, ... ], "followers": [ "Leslie", "Donna", "Tom" ... ], "has_extras": true }
  • 84.
    { a: “b”, c: { d:“e” ... }, f: [“g”, “h”, “i”], j: [ { k: “l” }, { m: “n” } ] } { a: “b”, c: { d: “e” ... }, f: [“g”, “h”, “i”], j: [ { k: “l” }, { m: “n” } ] } { a: “b”, c: { d: “e” ... }, f: [“g”, “h”, “i”], j: [ { k: “l” }, { m: “n” } ] } { a: “b”, c: { d: “e” ... }, f: [“g”, “h”, “i”], j: [ { k: “l” }, { m: “n” } ] }
  • 86.
  • 95.
    { ... a: “b”, ... c: { d:“e” ... }, ... }
  • 96.
  • 99.
    { "_id": 1, "first_name": "Leslie", "last_name":"Yepp", "cell": "8125552344", "city": "Pawnee", "location": [ -86.536632, 39.170344 ], "hobbies": [ "scrapbooking", "eating waffles", "working” ], "jobHistory": [ { "title": "Deputy Director", "yearStarted": 2004 }, { "title": "City Councillor", "yearStarted": 2012 }, { "title": "Director, National Parks Service, Midwest Branch", "yearStarted": 2014 } ] } { "_id": 1, "first_name": "Ron", "last_name": "Swandaughter", "cell": ”8125559347", "city": "Pawnee", "hobbies": [ ”woodworking", ”fishing" ], "jobHistory": [ { "title": "Director", "yearStarted": 2002 }, { "title": ”CEO, Kinda Good Building Company", "yearStarted": 2014 } ] } { "_id": 3, "first_name": "Lauren", "last_name": "Burhug", "city": "Pawnee", "hobbies": [ "soccer" ], "school": "Pawnee Elementary" }
  • 100.
    { a: “b”, c: { d:“e” ... }, f: [“g”, “h”, “i”], j: [ { k: “l” }, { m: “n” } ] }
  • 101.