Hey @ManiK welcome to the community !
it looks like you aren’t really returning anything from load_mongo_data function, probably what you want to do is,
@st.cache
def load_mongo_data(coll_name):
return list(db.coll_name.find())
But I think you are living dangerously there as the function might return a lot of records.
So I would recommend you to do a paginated query, something like this would be less heavy for your db and server,
Taking idea from this answer, Streamlit app disconnects and stops before displaying data
import streamlit as st
from math import ceil
page_size = 1000
@st.cache
def load_mongo_data(coll_name, page):
data = list(db[coll_name].find().skip((page-1)*page_size).limit(page_size))
return data
coll_name = st.sidebar.selectbox ("Select collection: ",db.list_collection_names())
document_count = db[coll_name].count_documents()
page_number = st.number_input(
label="Page Number",
min_value=1,
max_value=ceil(document_count /page_size),
step=1,
)
st.write(load_mongo_data(coll_name, page_number))
Its untested but its just intended to communicate the idea.
Hope it helps !