Files
broccolini-bot/scripts/test-mongodb.js
indifferentketchup fa7d4af132 strip: delete stale docs/ and broccolini_bot_context.md
Both were saturated with references to removed features.
Regenerate fresh post-MVP.
2026-04-21 16:32:05 +00:00

43 lines
989 B
JavaScript

/**
* Test MongoDB connection using the native driver.
* Uses MONGODB_URI from .env. Run: npm run test-mongodb
*/
require('dotenv').config();
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = (process.env.MONGODB_URI || '').trim();
const scheme = uri.split('://')[0];
if (!uri) {
console.error('MONGODB_URI is not set in .env');
process.exit(1);
}
if (scheme !== 'mongodb' && scheme !== 'mongodb+srv') {
console.error('MONGODB_URI must start with mongodb:// or mongodb+srv://');
process.exit(1);
}
const client = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
},
});
async function run() {
try {
await client.connect();
await client.db('admin').command({ ping: 1 });
console.log('Pinged your deployment. You successfully connected to MongoDB!');
} finally {
await client.close();
}
}
run().catch((err) => {
console.error(err);
process.exit(1);
});