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"); | |
| process.exit(1); | |
| } | |
| mongoose.connect(MONGO_URI) | |
| .then(async () => { | |
| console.log("β MongoDB Connected"); | |
| const Product = require('./src/models/Product'); // Adjust path if needed | |
| // 1. Update all products missing 'condition' | |
| const result = await Product.updateMany( | |
| { condition: { $exists: false } }, // Filter | |
| { $set: { condition: 'new' } } // Update | |
| ); | |
| console.log(`β Migrated ${result.modifiedCount} products to 'new' condition.`); | |
| process.exit(0); | |
| }) | |
| .catch(err => { | |
| console.error("β Error:", err); | |
| process.exit(1); | |
| }); | |