-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset.js
More file actions
30 lines (23 loc) · 922 Bytes
/
reset.js
File metadata and controls
30 lines (23 loc) · 922 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
const mongoose = require("mongoose");
require("dotenv").config();
const MONGO_URI = process.env.MONGO_URI;
async function resetDatabase() {
try {
console.log("🔄 درحال اتصال به MongoDB...");
await mongoose.connect(MONGO_URI);
console.log("✅ MongoDB متصل شد");
console.log("🗑️ درحال حذف تمام دادهها...");
// حذف تمام collections
const collections = await mongoose.connection.db.listCollections().toArray();
for (const collection of collections) {
await mongoose.connection.db.dropCollection(collection.name);
console.log(`✅ Collection "${collection.name}" حذف شد`);
}
console.log("✨ دیتابیس با موفقیت ریست شد!");
process.exit(0);
} catch (err) {
console.error("❌ خطا در ریست دیتابیس:", err.message);
process.exit(1);
}
}
resetDatabase();