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