Petl to export data to a mongodb collection in docker

Question:

I want to ingest data from a csv file into a mongodb collection ruining in a docker container by using just python. Do you have any idea how can I do so?

Asked By: Abdul Wassey

||

Answers:

from http import client
import pandas as pd  
from pymongo import MongoClient

client = MongoClient('mongodb://localhost:27017/',username="yourusername", password="yourpassword")

db = client['mydb']
data = pd.read_csv('formated_csv.csv')
data=data.to_dict(orient="records")
db.mycollection.insert_many(data)
Answered By: Abdul Wassey
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.