Spaces:
Configuration error
Configuration error
Download scripts/update_categories.js from sdsdsd55415/pcstore: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/sdsdsd55415/pcstore/resolve/main/scripts/update_categories.js
- Command line
-
hf download hf://spaces/sdsdsd55415/pcstore/scripts/update_categories.js
-
curl -L -o update_categories.js https://huggingface.co/spaces/sdsdsd55415/pcstore/resolve/main/scripts/update_categories.js
1.87 kB
| const mongoose = require('mongoose'); | |
| require('dotenv').config(); | |
| const Category = require('../src/models/Category'); | |
| const newCategories = [ | |
| { name: "Periferik qurilmalar B/U", description: "Ishlatilgan periferik qurilmalar (Sichqoncha, Klaviatura va h.k)" }, | |
| { name: "Periferik qurilmalar Yangi", description: "Yangi periferik qurilmalar" }, | |
| { name: "Kompyuterning asosiy qismlari B/U", description: "Ishlatilgan kompyuter ehtiyot qismlari (CPU, GPU, RAM)" }, | |
| { name: "Kompyuterning asosiy qismlari Yangi", description: "Yangi kompyuter ehtiyot qismlari" } | |
| ]; | |
| async function updateCategories() { | |
| try { | |
| await mongoose.connect(process.env.MONGO_URI); | |
| console.log('MongoDB Connected'); | |
| // Clear existing | |
| await Category.deleteMany({}); | |
| console.log('Old categories deleted.'); | |
| // Add new | |
| for (const cat of newCategories) { | |
| // Generate a simple ID if model requires it, checking model definition first | |
| // Assuming model has 'id' field which might be string or number. | |
| // Let's generate a unique string ID based on random or counter if needed. | |
| // Based on previous views, models usually have 'id'. | |
| // Let's use a random 6 digit ID for simplicity or auto-increment if logic exists. | |
| const newCat = new Category({ | |
| id: Math.floor(100000 + Math.random() * 900000).toString(), | |
| name: cat.name, | |
| description: cat.description | |
| }); | |
| await newCat.save(); | |
| console.log(`Added: ${cat.name}`); | |
| } | |
| console.log('All categories updated successfully!'); | |
| process.exit(); | |
| } catch (error) { | |
| console.error('Error:', error); | |
| process.exit(1); | |
| } | |
| } | |
| updateCategories(); | |