/** * Reorganize document categories as requested: * 1. Move implementation guides from getting-started to resources category * 2. Move Glossary from technical-reference to getting-started * 3. Ensure Research & Theory section is collapsed by default */ const { MongoClient } = require('mongodb'); require('dotenv').config({ path: '/var/www/tractatus/.env' }); async function run() { const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017'; const DB_NAME = process.env.MONGODB_DB || 'tractatus_prod'; const client = new MongoClient(MONGODB_URI); await client.connect(); console.log('═══════════════════════════════════════════════════════════'); console.log(' REORGANIZING DOCUMENT CATEGORIES'); console.log('═══════════════════════════════════════════════════════════\n'); const db = client.db(DB_NAME); const collection = db.collection('documents'); // 1. Find guides in Getting Started console.log('1️⃣ Finding implementation guides in Getting Started...\n'); const guides = await collection.find({ category: 'getting-started', slug: { $in: [ 'implementation-guide-v1.1', 'implementation-guide', 'implementation-guide-python-examples' ]} }).project({ slug: 1, title: 1 }).toArray(); console.log(`Found ${guides.length} guides:`); guides.forEach(g => console.log(` - ${g.slug}`)); // 2. Move guides to resources category if (guides.length > 0) { console.log('\n📝 Moving guides to resources category...\n'); const result = await collection.updateMany( { slug: { $in: guides.map(g => g.slug) } }, { $set: { category: 'resources', updated_at: new Date() } } ); console.log(`✅ Moved ${result.modifiedCount} guides to resources`); } // 3. Move Glossary to getting-started console.log('\n2️⃣ Moving Glossary to Getting Started...\n'); const glossaryResult = await collection.updateOne( { slug: 'GLOSSARY' }, { $set: { category: 'getting-started', order: 10, updated_at: new Date() } } ); if (glossaryResult.modifiedCount > 0) { console.log('✅ Glossary moved to getting-started (order: 10)'); } else { console.log('⚠️ Glossary not found or already in getting-started'); } // 4. Verify final state console.log('\n3️⃣ Verifying final categories...\n'); const gettingStarted = await collection.find({ category: 'getting-started', visibility: 'public' }) .project({ slug: 1, title: 1, order: 1 }) .sort({ order: 1 }) .toArray(); console.log(`Getting Started (${gettingStarted.length} documents):`); gettingStarted.forEach(d => console.log(` [${d.order}] ${d.slug}`)); const resources = await collection.find({ category: 'resources', visibility: 'public' }) .project({ slug: 1, title: 1, order: 1 }) .sort({ order: 1 }) .toArray(); console.log(`\nResources (${resources.length} documents):`); resources.forEach(d => console.log(` [${d.order || 'none'}] ${d.slug}`)); await client.close(); console.log('\n═══════════════════════════════════════════════════════════'); console.log(' REORGANIZATION COMPLETE'); console.log('═══════════════════════════════════════════════════════════\n'); } run().catch(console.error);