/** * Unarchive and publish the best Glossary document */ 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(' UNARCHIVING GLOSSARY'); console.log('═══════════════════════════════════════════════════════════\n'); const db = client.db(DB_NAME); const collection = db.collection('documents'); // Find all glossary documents const glossaries = await collection.find({ slug: { $regex: 'glossary', $options: 'i' } }).toArray(); console.log(`Found ${glossaries.length} glossary document(s)\n`); // Pick the one with most sections let best = null; let bestSections = 0; glossaries.forEach((doc, idx) => { const sections = doc.sections?.length || 0; console.log(`${idx + 1}. ${doc.slug}`); console.log(` Title: ${doc.title}`); console.log(` Sections: ${sections}`); console.log(` Visibility: ${doc.visibility}`); console.log(` Category: ${doc.category || 'none'}`); console.log(''); if (sections > bestSections) { best = doc; bestSections = sections; } }); if (!best) { console.log('❌ No glossary documents found'); await client.close(); return; } console.log(`✅ Best version: ${best.slug} (${bestSections} sections)\n`); // Unarchive it if (best.visibility !== 'public') { console.log('📝 Updating to public...\n'); const result = await collection.updateOne( { _id: best._id }, { $set: { visibility: 'public', category: 'technical-reference', order: 100, // Place at end of technical reference updated_at: new Date() } } ); console.log(`✅ Updated: ${result.modifiedCount} document(s)`); // Verify const updated = await collection.findOne( { _id: best._id }, { projection: { slug: 1, title: 1, visibility: 1, category: 1, order: 1 } } ); console.log('\n🔍 Verification:'); console.log(JSON.stringify(updated, null, 2)); } else { console.log('✅ Already public - no update needed'); } await client.close(); console.log('\n═══════════════════════════════════════════════════════════'); console.log(' COMPLETE'); console.log('═══════════════════════════════════════════════════════════\n'); } run().catch(console.error);