KrSharangrav
chatbot changes
8799fb1
raw
history blame
612 Bytes
import pymongo
import streamlit as st
# MongoDB Connection
def get_mongo_connection():
"""Establish connection to MongoDB."""
try:
client = pymongo.MongoClient(st.secrets["mongo_uri"])
db = client["twitter_db"]
collection = db["sentiments"]
return collection
except Exception as e:
st.error(f"MongoDB connection error: {e}")
return None
def get_mongo_data():
"""Fetch first 5 rows from MongoDB collection."""
collection = get_mongo_connection()
if collection:
return list(collection.find({}, {"_id": 0}).limit(5))
return None