Forums

Full Version: Write data to a MongoDB collection using python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Use python script component.
Paste below script in meta information script section.

import pandas as pd
from pymongo import MongoClient

def myconnect(data):
  df = data
  client = MongoClient("mongodb://localhost:27017/") #connection_string
  mydatabase = client.db_name #dbname
  mycollection = mydatabase.collection_name #collection_name
 
  mycollection.insert_many(df.to_dict('records'))
  client.close()