-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo.ts
42 lines (33 loc) · 919 Bytes
/
mongo.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
import mongoose, {Mongoose} from 'mongoose';
import * as dotenv from 'dotenv';
import loggerService from './services/loggerService';
dotenv.config();
class Mongo {
private mongoose: Mongoose;
constructor() {
this.mongoose = mongoose;
}
async connect() {
await this.mongoose.connect(
process.env.NODE_ENV === 'test' ? process.env.TEST_URI : process.env.URI,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
},
);
}
async disconnect() {
await this.mongoose.disconnect();
loggerService.title('Mongo disconnected');
}
async bootstrap() {
await this.connect();
loggerService.title('MongoDB ready');
}
getClient() {
return this.mongoose;
}
}
const instance = new Mongo();
export default instance;