township-chatbot / mongo.py
puseletso55's picture
Update mongo.py
2b1769d verified
raw
history blame contribute delete
553 Bytes
import os
from pymongo import MongoClient
from dotenv import load_dotenv
load_dotenv() # Load .env file
MONGODB_URI = os.getenv("MONGODB_URI")
client = MongoClient(MONGODB_URI)
db = client["township_directory"]
businesses_collection = db["businesses"]
def insert_business(business):
businesses_collection.insert_one(business)
def find_businesses_by_location(location_str):
# Simple text match, but can be improved using geospatial queries
return list(businesses_collection.find({"location": {"$regex": location_str, "$options": "i"}}))