-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
executable file
·29 lines (23 loc) · 734 Bytes
/
Copy pathdb.js
File metadata and controls
executable file
·29 lines (23 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
25
26
27
28
29
// Contains the class DBClient
import mongodb from 'mongodb';
class DBClient {
constructor() {
const host = process.env.DB_HOST || 'localhost';
const port = process.env.DB_PORT || 27017;
const database = process.env.DB_DATABASE || 'files_manager';
const dbURL = `mongodb://${host}:${port}/${database}`;
this.client = new mongodb.MongoClient(dbURL, { useUnifiedTopology: true });
this.client.connect();
}
isAlive() {
return this.client.isConnected();
}
async nbUsers() {
return this.client.db().collection('users').countDocuments();
}
async nbFiles() {
return this.client.db().collection('files').countDocuments();
}
}
const dbClient = new DBClient();
export default dbClient;