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

routers/lesson10.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)

Try It
See ../../Routes and Templates/Python (FastAPI) to create a test environment.