Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
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.
Solved! Go to 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)
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
@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)
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!
Check out the July 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 30 | |
| 29 | |
| 25 | |
| 23 | |
| 16 |
| User | Count |
|---|---|
| 45 | |
| 32 | |
| 17 | |
| 16 | |
| 16 |