0

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?

1 Answers1

0
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)
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 31 '22 at 19:38