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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
CLaudia2_silva
Frequent Visitor

Write Back to MongoDB from Power BI

I'm trying to collect information from a table I have in Power BI in MongoDB.
After creating the table, I created a "MongoDB Insert" column in which I insert the data and after that I invoked a custom column that has the connection to the database, however it is returning an error..
Could someone help me to understand where I'm going wrong?


Thank you for the help!

 

CLaudia2_silva_0-1678365923736.png

 

CLaudia2_silva_0-1678365704333.png

CLaudia2_silva_1-1678365720519.png

CLaudia2_silva_2-1678365771376.png

 

I have already unchecked the checkbox under Options ->Security -> "Require user approval for new native database queries".  I still get the same error with this unchecked.

1 ACCEPTED SOLUTION
CLaudia2_silva
Frequent Visitor

Hoping to be able to help someone, I leave the solution found.


Code for the MongoDB Insert function:

 

= Table.AddColumn(#"Changed Type", "MongoDB Insert", each "{
'id':" & Text.From([ID]) & ",
'start_time': '" & Text.From([start_time]) & "',
'feedback': '" & Text.From([feedback]) & "'}")

 

Code for the invoked function:

 

(insert_statement as text)=>
let

Insert = Python.Execute("import pymongo; client = pymongo.MongoClient('mongodb://localhost:27017/'); db = client['database-name']; collection = db['collection-name']; data = " & insert_statement & "; result = collection.insert_one(data);")

in
Insert

 

 

Thanks!!

 

View solution in original post

1 REPLY 1
CLaudia2_silva
Frequent Visitor

Hoping to be able to help someone, I leave the solution found.


Code for the MongoDB Insert function:

 

= Table.AddColumn(#"Changed Type", "MongoDB Insert", each "{
'id':" & Text.From([ID]) & ",
'start_time': '" & Text.From([start_time]) & "',
'feedback': '" & Text.From([feedback]) & "'}")

 

Code for the invoked function:

 

(insert_statement as text)=>
let

Insert = Python.Execute("import pymongo; client = pymongo.MongoClient('mongodb://localhost:27017/'); db = client['database-name']; collection = db['collection-name']; data = " & insert_statement & "; result = collection.insert_one(data);")

in
Insert

 

 

Thanks!!

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors