Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

Commit ad1e8e9

Browse files
author
bhasher
committed
Customize mangoDB connection
1 parent 000f51e commit ad1e8e9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/db/MongoDB.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class MongoDB {
1515
// TODO handle error
1616
// TODO change using BULK write
1717
constructor (username, password, host, database, port) {
18-
this.client = new MongoClient(`mongodb://127.0.0.1:36175/51a8b34f-d253-4cc3-8ed6-96d0ce9c03d5?`);
18+
this.client = new MongoClient(`mongodb://${username}:${password}@${host}:${port}/?retryWrites=true&w=majority`);
1919
}
2020

2121
async connect () {
@@ -50,7 +50,7 @@ class MongoDB {
5050
async setLine (documentId, uuid, content) {
5151
await this.documentsCollection.updateOne({_id: ObjectID(documentId), 'content.uuid': uuid}, {$set: {'content.$.content': content}});
5252
}
53-
53+
5454
async newLine (documentId, previousUuid, uuid, content) {
5555
// Insert a line at the right place
5656
//TODO is it possible in one operation
@@ -94,9 +94,15 @@ class MongoDB {
9494
}
9595

9696
function getDB () {
97-
db = new MongoDB(configs.DB_USERNAME, configs.DB_PASSWORD, configs.DB_HOST, configs.DB_DATABASE, configs.DB_PORT);
97+
db = new MongoDB(
98+
configs.DB_CONFIG.DB_USERNAME,
99+
configs.DB_CONFIG.DB_PASSWORD,
100+
configs.DB_CONFIG.DB_HOST,
101+
configs.DB_CONFIG.DB_DATABASE,
102+
configs.DB_CONFIG.DB_PORT
103+
);
98104
db.connect();
99105
return db
100106
}
101107

102-
module.exports = getDB();
108+
module.exports = getDB();

0 commit comments

Comments
 (0)