/** * Compare Glossary documents in dev and production */ const { MongoClient } = require('mongodb'); require('dotenv').config({ path: '/var/www/tractatus/.env' }); async function run() { console.log('═══════════════════════════════════════════════════════════'); console.log(' COMPARING GLOSSARY DOCUMENTS'); console.log('═══════════════════════════════════════════════════════════\n'); // Check dev const devClient = new MongoClient('mongodb://localhost:27017'); await devClient.connect(); const devDocs = await devClient.db('tractatus_dev').collection('documents').find({ slug: { $regex: 'glossary', $options: 'i' } }).project({ slug: 1, title: 1, visibility: 1, category: 1, sections: 1 }).toArray(); await devClient.close(); console.log(`📚 DEV Database: ${devDocs.length} glossary document(s)\n`); devDocs.forEach((doc, idx) => { console.log(`${idx + 1}. ${doc.title}`); console.log(` Slug: ${doc.slug}`); console.log(` Visibility: ${doc.visibility}`); console.log(` Category: ${doc.category || 'none'}`); console.log(` Sections: ${doc.sections?.length || 0}`); console.log(''); }); // Check production const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017'; const DB_NAME = process.env.MONGODB_DB || 'tractatus_prod'; const prodClient = new MongoClient(MONGODB_URI); await prodClient.connect(); const prodDocs = await prodClient.db(DB_NAME).collection('documents').find({ slug: { $regex: 'glossary', $options: 'i' } }).project({ slug: 1, title: 1, visibility: 1, category: 1, sections: 1 }).toArray(); await prodClient.close(); console.log(`📦 PRODUCTION Database: ${prodDocs.length} glossary document(s)\n`); prodDocs.forEach((doc, idx) => { console.log(`${idx + 1}. ${doc.title}`); console.log(` Slug: ${doc.slug}`); console.log(` Visibility: ${doc.visibility}`); console.log(` Category: ${doc.category || 'none'}`); console.log(` Sections: ${doc.sections?.length || 0}`); console.log(''); }); console.log('═══════════════════════════════════════════════════════════'); console.log(' RECOMMENDATION'); console.log('═══════════════════════════════════════════════════════════\n'); // Find the best one const allDocs = [...devDocs.map(d => ({...d, source: 'dev'})), ...prodDocs.map(d => ({...d, source: 'prod'}))]; const best = allDocs.reduce((best, doc) => { const sectionsCount = doc.sections?.length || 0; const bestSections = best.sections?.length || 0; return sectionsCount > bestSections ? doc : best; }, allDocs[0]); if (best) { console.log(`Best version: ${best.slug} (${best.source})`); console.log(` ${best.sections?.length || 0} sections`); console.log(` Currently: ${best.visibility}`); console.log(''); if (best.visibility !== 'public') { console.log('✅ Action: Unarchive this document and set visibility=public'); } else { console.log('✅ Already public - no action needed'); } } console.log(''); } run().catch(console.error);