Forums

Full Version: How to read a MongoDB collection using python in pipeline?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Use python script component.
Under meta information paste below script in script section.
Provide required credentials.
import pandas as pd
from pymongo import MongoClient
def myread():
    client = MongoClient("mongodb://localhost:27017/"#connection_string
    mydatabase = client.db_name#cdatabase_name
    mycollection = mydatabase.collection_name #collection_name
    cursor = mycollection.aggregate([ { '$project': { '_id': 0}}]) #aggregate_query
    df = pd.DataFrame(list(cursor))
    client.close()
    return df
myread()