File size: 708 Bytes
e0356a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File: src/insert_data.py
import pandas as pd
from pymongo import MongoClient

# Configuration (can also be set via config.yaml)
MONGO_URI = "mongodb://localhost:27017/"
DB_NAME = "customer_db"
COLLECTION_NAME = "customers"

def insert_data():
    client = MongoClient(MONGO_URI)
    db = client[DB_NAME]
    collection = db[COLLECTION_NAME]
    
    # Load data from CSV
    df = pd.read_csv("data\\customers.csv")
    records = df.to_dict(orient="records")
    collection.delete_many({})  
    collection.insert_many(records)
    print(f" Inserted {len(records)} records into MongoDB collection '{COLLECTION_NAME}' in DB '{DB_NAME}'.")

if __name__ == "__main__":
    insert_data()