const mongoose = require('mongoose'); require('dotenv').config(); const MONGO_URI = process.env.MONGO_URI; if (!MONGO_URI) { console.error("❌ MONGO_URI is missing in .env"); process.exit(1); } mongoose.connect(MONGO_URI) .then(async () => { console.log("✅ MongoDB Connected"); const db = mongoose.connection.db; const collections = await db.listCollections().toArray(); console.log(`đŸ“Ļ Collections: ${collections.map(c => c.name).join(', ')}`); // Check 'orders' collection indexes if (collections.find(c => c.name === 'orders')) { const indexes = await db.collection('orders').indexes(); console.log("🔍 'orders' Indexes:", indexes); // Drop 'orderId_1' if exists const textIndex = indexes.find(i => i.name === 'orderId_1'); if (textIndex) { await db.collection('orders').dropIndex('orderId_1'); console.log("✅ Dropped obsolete index: orderId_1"); } else { console.log("â„šī¸ Index 'orderId_1' not found."); } } console.log("🏁 Done."); process.exit(0); }) .catch(err => { console.error("❌ Error:", err); process.exit(1); });