-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmon_kick.py
executable file
·40 lines (33 loc) · 1.34 KB
/
mon_kick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/home/sgrosu/anaconda2/bin/python
"""
Your task is to sucessfully run the exercise to see how pymongo works
and how easy it is to start using it.
You don't actually have to change anything in this exercise,
but you can change the city name in the add_city function if you like.
Your code will be run against a MongoDB instance that we have provided.
If you want to run this code locally on your machine,
you have to install MongoDB (see Instructor comments for link to installation information)
and uncomment the get_db function.
"""
def add_city(db):
# Changes to this function will be reflected in the output.
# All other functions are for local use only.
# Try changing the name of the city to be inserted
db.cities.insert({"name" : "Chicago"})
def get_city(db):
#return db.restaurants.find({'cuisine':'Romanian'}).next()
return db.cities.find_one()
def get_db():
# For local use
from pymongo import MongoClient
import urllib
password = urllib.quote_plus('P@ssw0rd')
client = MongoClient('mongodb://admin:'+password+'@127.0.0.1')
# 'examples' here is the database name. It will be created if it does not exist.
db = client.examples
return db
if __name__ == "__main__":
# For local use
db = get_db() # uncomment this line if you want to run this locally
add_city(db)
print get_city(db)