const { MongoClient } = require('mongodb');

(async () => {
  const client = new MongoClient('mongodb://localhost:27017/tractatus_dev');
  await client.connect();
  const docs = await client.db('tractatus_dev').collection('documents')
    .find({}, { projection: { slug: 1, title: 1, sections: 1, category: 1 } })
    .sort({ slug: 1 })
    .toArray();

  const withSections = docs.filter(d => d.sections && d.sections.length > 0);
  const without = docs.filter(d => !d.sections || d.sections.length === 0);

  console.log('=== DOCUMENTS WITH SECTIONS (' + withSections.length + ') ===');
  withSections.forEach(d => console.log('-', d.slug, '(' + d.sections.length + ' sections, cat:' + (d.category || 'none') + ')'));

  console.log('\n=== DOCUMENTS WITHOUT SECTIONS (' + without.length + ') ===');
  without.forEach(d => console.log('-', d.slug, '(cat:' + (d.category || 'none') + ')'));

  await client.close();
})();
