Monorepo for Aesthetic.Computer aesthetic.computer
at main 68 lines 2.1 kB view raw
1#!/usr/bin/env node 2 3import { MongoClient } from 'mongodb'; 4 5const MONGODB_CONNECTION_STRING = process.env.MONGODB_CONNECTION_STRING; 6const MONGODB_NAME = process.env.MONGODB_NAME || 'aesthetic'; 7 8async function main() { 9 const client = new MongoClient(MONGODB_CONNECTION_STRING); 10 11 try { 12 await client.connect(); 13 console.log('Connected to MongoDB\n'); 14 15 const db = client.db(MONGODB_NAME); 16 17 // List all collections 18 console.log('Collections in database:'); 19 const collections = await db.listCollections().toArray(); 20 for (const coll of collections) { 21 console.log(` - ${coll.name}`); 22 } 23 24 // Check for chat-related collections 25 console.log('\n='.repeat(80)); 26 const chatCollections = collections.filter(c => 27 c.name.toLowerCase().includes('chat') || 28 c.name.toLowerCase().includes('message') 29 ); 30 31 if (chatCollections.length > 0) { 32 console.log('\nChat-related collections found:'); 33 34 for (const coll of chatCollections) { 35 console.log(`\n${coll.name}:`); 36 const collection = db.collection(coll.name); 37 const count = await collection.countDocuments(); 38 console.log(` Total documents: ${count}`); 39 40 if (count > 0) { 41 const sample = await collection.findOne(); 42 console.log(` Sample document:`); 43 console.log(JSON.stringify(sample, null, 2)); 44 } 45 } 46 } else { 47 console.log('\nNo chat-related collections found. Checking all collections for messages...\n'); 48 49 for (const coll of collections) { 50 const collection = db.collection(coll.name); 51 const count = await collection.countDocuments(); 52 if (count > 0) { 53 const sample = await collection.findOne(); 54 console.log(`\n${coll.name} (${count} documents):`); 55 console.log(JSON.stringify(sample, null, 2).substring(0, 500) + '...'); 56 } 57 } 58 } 59 60 } catch (error) { 61 console.error('Error:', error.message); 62 process.exit(1); 63 } finally { 64 await client.close(); 65 } 66} 67 68main();