Server-Side Scripting/Document Databases/Python (Flask)

app.py
"   return result

def country_exists(country): mongo = pymongo.MongoClient(HOST) database = mongo[DATABASE] collection = database[COLLECTION] filter = { "country": country }   return bool(collection.count(filter))

def insert_country(country, temperature): mongo = pymongo.MongoClient(HOST) database = mongo[DATABASE] collection = database[COLLECTION] document = { "country": country, "temperature": temperature }   collection.insert_one(document)

def update_country(country, temperature): mongo = pymongo.MongoClient(HOST) database = mongo[DATABASE] collection = database[COLLECTION] filter = { "country": country }   update = { "$set": { "temperature": temperature } }   collection.update_one(filter, update)

def delete_country(country): mongo = pymongo.MongoClient(HOST) database = mongo[DATABASE] collection = database[COLLECTION] filter = { "country": country }   collection.delete_one(filter)

if __name__ == "__main__": app.run(host='0.0.0.0', port=5000)

Try It

 * 1) Use Docker/MongoDB to run a MongoDB server.
 * 2) Use Docker/Flask and copy and paste the code above to run as the flask application. Be sure to modify the MongoDB host address to match the address received by your MongoDB server.