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
Active
Viewed 66 times
0

Abdul Wassey
- 5
- 2
-
You could also try mongoimport. https://www.mongodb.com/docs/database-tools/mongoimport/ – VarChar42 Jul 26 '22 at 10:58
1 Answers
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)

Abdul Wassey
- 5
- 2
-
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