-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitial_data_load.py
32 lines (26 loc) · 991 Bytes
/
initial_data_load.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# initial_data_load.py
from pymongo import MongoClient
# MongoDB Client
mongo_client = MongoClient("mongodb://127.0.0.1:27017/?replicaSet=rs0")
db = mongo_client["ecommerce"]
# Collections
users_collection = db["users"]
items_collection = db["items"]
def add_initial_data():
# Adding initial data to MongoDB
users = [
{"user_id": 1, "name": "Susmit", "email": "[email protected]"},
{"user_id": 2, "name": "Ishan", "email": "[email protected]"},
{"user_id": 3, "name": "Amandeep", "email": "[email protected]"}
]
items = [
{"item_id": 101, "name": "Laptop", "price": 1200},
{"item_id": 102, "name": "Phone", "price": 800},
{"item_id": 103, "name": "Table", "price": 150},
{"item_id": 104, "name": "Chair", "price": 75}
]
users_collection.insert_many(users)
items_collection.insert_many(items)
print("Initial data added to MongoDB successfully")
if __name__ == "__main__":
add_initial_data()