Spaces:
Paused
Paused
| 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); | |
| }); | |