-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_schema.py
More file actions
29 lines (23 loc) · 859 Bytes
/
fix_schema.py
File metadata and controls
29 lines (23 loc) · 859 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
import os
from pymongo import MongoClient
from dotenv import load_dotenv
load_dotenv()
MONGO_URI = os.getenv("MONGO_URI")
client = MongoClient(MONGO_URI, tlsAllowInvalidCertificates=True)
db = client["layover_os"]
collection = db["amenities"]
print("🔄 Starting Migration: terminal -> terminal_id")
# Update all documents that have 'terminal' but missing 'terminal_id'
# using an aggregation pipeline for efficiency
result = collection.update_many(
{"terminal": {"$exists": True}},
[{"$set": {"terminal_id": "$terminal"}}]
)
print(f"✅ Matched {result.matched_count} documents.")
print(f"✅ Modified {result.modified_count} documents.")
# Verify
doc = collection.find_one()
print("\n🔍 Sample Document After Fix:")
print(f"Name: {doc.get('name')}")
print(f"Terminal: {doc.get('terminal')}")
print(f"Terminal ID: {doc.get('terminal_id')}")