telegram-shop-api / scripts /migrate_condition.js
Deploy Bot
Feat: Smart Product Condition Logic
1e82281
raw
history blame contribute delete
827 Bytes
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);
});