I tried to connect the MongoDB server using streamlit selection box feature, but I cant get the collection list on my dropdown selection box. Here's my code
%%writefile app.py
import streamlit as st
import pymongo
from pymongo import MongoClient
import pandas as pd
import numpy as np
st.header('Import Well Log into MongoDB Server')
mongoClient = MongoClient ('mongodb://localhost:27017/')
database_names = mongoClient.list_database_names()
optmongo = st.selectbox('Choose the database',(database_names))
my_db2 = mongoClient.optmongo
collection_list = my_db2.list_collection_names()
optmongo2 = st.selectbox('Choose the collection',(collection_list))
my_cols2 = my_db2.optmongo2
Help, this is what I get (screenshot streamlit apps)
I cant get the list collection names
CodePudding user response:
Change:
my_db2 = mongoClient.optmongo
To
my_db2 = mongoClient[optmongo]