Forum Discussion
MongoDB Data is not showing in powerbi by using python script
import pymongo
from pymongo import MongoClient
connection = pymongo.MongoClient("mongodb+srv://<username>:<password>@cluster0.zev7c.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
db=connection['study']
collection=db['college']
one = collection.find_one({'studentName':"Gopi"})
print(one)
when I run this code in python showing the result
{'_id': ObjectId('6174eb2d3d927d29a8d0b271'), 'studentid': 2, 'studentName': 'Gopi', 'Branch': 'Electrical', 'joinedyear': 2018, 'Hostel': 'A2'}
but when I run the same code in Powerbi Data is not showing.
This seemed to work:
# Specify the collection name
collection = db['your_collection_name']
# Perform the query
query = {} # Your query conditions here
result = collection.find(query)
# Convert the query result to a DataFrame
df = pd.DataFrame(result)
# Print the DataFrame
print(df)
3 Replies
- TomMartensSuper User
Hey sharath123 ,
make sure that the result that you want to use inside PowerBI is a dataframe, I assume you can "convert" your JSON object using Pandas.
Hopefully, this provides what you are looking for.
Regards,
Tom
- sharath123Helper I
TomMartens thanks. but how to convert this result into a data frame?
please provide the syntax to convert the result into a data frame, so that I run the script in powerbi.- loch45New Member
This seemed to work:
# Specify the collection name
collection = db['your_collection_name']
# Perform the query
query = {} # Your query conditions here
result = collection.find(query)
# Convert the query result to a DataFrame
df = pd.DataFrame(result)
# Print the DataFrame
print(df)