-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogDatabaseData.ts
47 lines (43 loc) · 1.5 KB
/
logDatabaseData.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import mongoose, { MongooseError } from 'mongoose';
import { TokenModel } from './src/database/models/tokenModel';
async function dropTokenCollection(): Promise<void> {
try {
// Ensure you are connected before trying to drop the collection
await mongoose.connect('mongodb://localhost:27017/opendevbot', { autoIndex: true });
// Use the native MongoDB driver to drop the collection
const result = await TokenModel.collection.drop({ dbName: 'opendevbot', maxTimeMS: 10000 });
console.log('TokenModel collection dropped successfully:', result);
} catch (error: unknown) {
if (error instanceof Error) {
// Handle the error
console.error('Error dropping TokenModel collection:', error);
}
}
}
// Wrapping in an async function
async function main() {
try {
await dropTokenCollection().catch((error: Error) => {
if (error instanceof Error) {
console.error('Error dropping TokenModel collection:', error);
}
if (error instanceof MongooseError) {
// Handle the error
console.error('Mongoose error:', error.cause + ': ' + error.name + ': ' + error.message + ': ' + error.stack);
}
});
} catch (error: unknown) {
if (error instanceof Error) {
// Handle the error
console.error('Error dropping TokenModel collection:', error);
}
} finally {
await mongoose.disconnect();
}
}
// Call the main function
main().catch((error: unknown) => {
if (error instanceof Error) {
console.error('Error: ', error.cause + ': ' + error.name + ': ' + error.message + ': ' + error.stack);
}
});