|
|
|
import pandas as pd
|
|
from pymongo import MongoClient
|
|
|
|
|
|
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]
|
|
|
|
|
|
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()
|
|
|