mongodb-ops 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/mongodb-ops.js +3 -14
- package/package.json +1 -1
package/lib/mongodb-ops.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const MongoClient = require('mongodb').MongoClient;
|
|
4
4
|
const ObjectID = require('mongodb').ObjectID;
|
|
5
|
-
const DEFAULT_POOLSIZE = 5;
|
|
6
5
|
|
|
7
6
|
class MongoDBOps {
|
|
8
7
|
/**
|
|
@@ -36,10 +35,9 @@ class MongoDBOps {
|
|
|
36
35
|
* Static method - Get DB client - It supports multiple db client with different connection string. Active db client will be reused for better performance
|
|
37
36
|
*
|
|
38
37
|
* @param {string} connString Database connection string
|
|
39
|
-
* @param {number} [poolSize] Database client pool size
|
|
40
38
|
* @returns {promise} Promise with db client
|
|
41
39
|
*/
|
|
42
|
-
static async getDbClient(connString
|
|
40
|
+
static async getDbClient(connString) {
|
|
43
41
|
if (!connString) { throw new Error("missing-connection-string"); }
|
|
44
42
|
|
|
45
43
|
if (!Array.isArray(MongoDBOps.dbClientList)) { MongoDBOps.dbClientList = []; }
|
|
@@ -47,23 +45,14 @@ class MongoDBOps {
|
|
|
47
45
|
for (let item of MongoDBOps.dbClientList) {
|
|
48
46
|
if (item.s.url === connString) {
|
|
49
47
|
if (item.topology.s.state !== "connected") {
|
|
50
|
-
item = await MongoClient.connect(connString
|
|
51
|
-
poolSize: poolSize !== DEFAULT_POOLSIZE ? poolSize : MongoDBOps.poolSize || DEFAULT_POOLSIZE,
|
|
52
|
-
useNewUrlParser: true,
|
|
53
|
-
useUnifiedTopology: true,
|
|
54
|
-
});
|
|
48
|
+
item = await MongoClient.connect(connString);
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
return Promise.resolve(item);
|
|
58
52
|
}
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
const newDbClient = await MongoClient.connect(connString
|
|
62
|
-
poolSize: poolSize !== DEFAULT_POOLSIZE ? poolSize : MongoDBOps.poolSize || DEFAULT_POOLSIZE,
|
|
63
|
-
useNewUrlParser: true,
|
|
64
|
-
useUnifiedTopology: true,
|
|
65
|
-
});
|
|
66
|
-
|
|
55
|
+
const newDbClient = await MongoClient.connect(connString);
|
|
67
56
|
MongoDBOps.dbClientList.push(newDbClient);
|
|
68
57
|
|
|
69
58
|
return Promise.resolve(newDbClient);
|