-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_db.js
More file actions
24 lines (19 loc) · 734 Bytes
/
check_db.js
File metadata and controls
24 lines (19 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const mongoose = require('mongoose');
require('dotenv').config({ path: './backend/.env' });
const checkDb = async () => {
try {
const db = process.env.MONGODB_URL || "mongodb://localhost:27017/pin_quest";
console.log('Connecting to:', db.replace(/:([^:@]+)@/, ':****@'));
await mongoose.connect(db);
console.log('Connected!');
const count = await mongoose.connection.db.collection('posts').countDocuments();
console.log('Total posts:', count);
const usersCount = await mongoose.connection.db.collection('users').countDocuments();
console.log('Total users:', usersCount);
process.exit(0);
} catch (err) {
console.error('Error:', err);
process.exit(1);
}
};
checkDb();