-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathload.py
More file actions
30 lines (22 loc) · 758 Bytes
/
load.py
File metadata and controls
30 lines (22 loc) · 758 Bytes
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
import json
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from dotenv import load_dotenv
import os
load_dotenv()
URI = os.getenv('MONGO_URI')
# Connect to MongoDB
client = MongoClient(URI, server_api=ServerApi('1'))
db = client['scholarship_db']
scholarships = db['scholarships']
# Load JSON data from file
with open('scrape.json', 'r') as file:
scholarship_data = json.load(file)
# Insert scholarships into MongoDB
for scholarship in scholarship_data:
# Insert the scholarship
result = scholarships.insert_one(scholarship)
print(f"Inserted scholarship with ID: {result.inserted_id}")
print(f"Total scholarships inserted: {len(scholarship_data)}")
# Close the MongoDB connection
client.close()