Created
June 3, 2024 07:47
-
-
Save syedjaferk/b9b60b24d5b0cd469dc68bef81504315 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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