Spaces:
Configuration error
Configuration error
Download scripts/migrate_condition.js from sdsdsd55415/pcstore: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/spaces/sdsdsd55415/pcstore/resolve/main/scripts/migrate_condition.js
- Command line
-
hf download hf://spaces/sdsdsd55415/pcstore/scripts/migrate_condition.js
-
curl -L -o migrate_condition.js https://huggingface.co/spaces/sdsdsd55415/pcstore/resolve/main/scripts/migrate_condition.js
857 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); | |
| }); | |