forked from koushik369mondal/WanderLust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-admin.js
More file actions
33 lines (26 loc) · 972 Bytes
/
make-admin.js
File metadata and controls
33 lines (26 loc) · 972 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
25
26
27
28
29
30
31
32
33
// Quick script to make a user admin
const mongoose = require('mongoose');
const User = require('./models/user');
// Connect to database
const MONGO_URL = process.env.ATLAS_DB_URL || "mongodb://127.0.0.1:27017/wanderlust";
async function makeAdmin() {
try {
await mongoose.connect(MONGO_URL);
console.log('Connected to MongoDB');
// Change 'your_username' to the actual username you want to make admin
const username = 'your_username'; // CHANGE THIS
const result = await User.updateOne(
{ username: username },
{ $set: { isAdmin: true } }
);
if (result.matchedCount > 0) {
console.log(`✅ User '${username}' is now an admin!`);
} else {
console.log(`❌ User '${username}' not found`);
}
await mongoose.disconnect();
} catch (error) {
console.error('Error:', error);
}
}
makeAdmin();