Skip to content

Instantly share code, notes, and snippets.

@syedjaferk
Created June 3, 2024 07:47
Show Gist options
  • Save syedjaferk/b9b60b24d5b0cd469dc68bef81504315 to your computer and use it in GitHub Desktop.
Save syedjaferk/b9b60b24d5b0cd469dc68bef81504315 to your computer and use it in GitHub Desktop.
from fastapi import FastAPI, HTTPException
from pymongo.mongo_client import MongoClient
app = FastAPI()
# Mongo Db Connection
MONGO_CONN_STR = "mongodb://localhost:27017"
mongo_client = MongoClient(MONGO_CONN_STR)
database = mongo_client['ulid_vs_uuid']
collection = database["uuid_with_index"]
@app.get("/ids/{id_val}")
def read_item(id_val: str):
res = collection.find_one({"id": id_val}, {'_id':0})
if res['id'] == id_val:
return {"status": "success"}
else:
return {"status": "failure"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment