Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
sharath123
Helper I
Helper I

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.


Capture.PNG

1 ACCEPTED SOLUTION

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)

View solution in original post

3 REPLIES 3
TomMartens
Super User
Super 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



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@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. 

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)

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors