Files
Deep-Package-Inspection/scripts/export-local-db.js
T
rafif dd4c8f6876 feat(source2): push all latest files - device labeling, help system, proxy docs, database isolation fix
- Added DOKUMENTASI-FILTER-PER-SITE.md (site isolation docs)
- Fixed start-with-env.js to force-load .env.production
- Fixed MONGODB_URI hostname from mongodb-netify to mongodb.prod.proit.id
- Updated .gitignore to exclude sensitive scripts and credential files
- Minor UI and labeling improvements
2026-07-29 14:14:29 +07:00

43 lines
1.3 KiB
JavaScript

// scripts/export-local-db.js
const { MongoClient } = require('mongodb');
const fs = require('fs');
const path = require('path');
const LOCAL_URI = 'mongodb://127.0.0.1:27017/backone_dpi';
const DB_NAME = 'backone_dpi';
const COLLECTIONS_TO_EXPORT = ['users', 'tenantconfigs', 'customagentlocations'];
const OUTPUT_DIR = path.join(__dirname, '..', 'migration-temp');
async function main() {
console.log('Connecting to local MongoDB...');
const client = new MongoClient(LOCAL_URI);
try {
await client.connect();
console.log('✓ Connected to local MongoDB successfully.');
const db = client.db(DB_NAME);
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR);
}
for (const colName of COLLECTIONS_TO_EXPORT) {
console.log(`Exporting collection: ${colName}...`);
const documents = await db.collection(colName).find({}).toArray();
const filePath = path.join(OUTPUT_DIR, `${colName}.json`);
fs.writeFileSync(filePath, JSON.stringify(documents, null, 2));
console.log(` ✓ Exported ${documents.length} documents to ${filePath}`);
}
console.log('\n✓ Database export complete!');
} catch (err) {
console.error('✗ Export failed:', err.message);
process.exit(1);
} finally {
await client.close();
}
}
main();