Monorepo for Aesthetic.Computer
aesthetic.computer
1#!/usr/bin/env node
2// explore-collections.mjs - See what collections exist and sample their schema
3
4import { config } from 'dotenv';
5import { fileURLToPath } from 'url';
6import { dirname, join } from 'path';
7import { connect } from '../../../system/backend/database.mjs';
8
9// Load environment from vault
10const __filename = fileURLToPath(import.meta.url);
11const __dirname = dirname(__filename);
12const vaultEnvPath = join(__dirname, '../../../aesthetic-computer-vault/at/.env');
13config({ path: vaultEnvPath });
14
15try {
16 const database = await connect();
17
18 console.log('\n🗄️ Database Collections:\n');
19
20 // List all collections
21 const collections = await database.db.listCollections().toArray();
22
23 console.log(`Found ${collections.length} collections:\n`);
24
25 for (const coll of collections) {
26 console.log(`📁 ${coll.name}`);
27
28 // Get a sample document
29 const collection = database.db.collection(coll.name);
30 const sample = await collection.findOne({});
31
32 if (sample) {
33 console.log(' Sample document:');
34 const keys = Object.keys(sample);
35 keys.forEach(key => {
36 const value = sample[key];
37 const type = Array.isArray(value) ? 'array' : typeof value;
38 const preview = type === 'string' && value.length > 50
39 ? value.substring(0, 47) + '...'
40 : type === 'object' && value !== null
41 ? '{...}'
42 : value;
43 console.log(` ${key}: ${type} = ${JSON.stringify(preview)}`);
44 });
45 } else {
46 console.log(' (empty collection)');
47 }
48 console.log('');
49 }
50
51 await database.disconnect();
52} catch (error) {
53 console.error('❌ Error:', error.message);
54 process.exit(1);
55}