Spaces:
Paused
Paused
File size: 827 Bytes
1e82281 | 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 31 | 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);
});
|