@cocreate/mongodb 1.10.5 → 1.10.6
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/index.js +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.10.6](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.10.5...v1.10.6) (2023-10-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* ensure a single connection is created ([f3856af](https://github.com/CoCreate-app/CoCreate-mongodb/commit/f3856afb83b59c314f73c11654f8aceaf4891bc7))
|
|
7
|
+
|
|
1
8
|
## [1.10.5](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.10.4...v1.10.5) (2023-10-25)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -6,12 +6,12 @@ const clients = new Map()
|
|
|
6
6
|
async function dbClient(data) {
|
|
7
7
|
if (data.storageUrl) {
|
|
8
8
|
let client = clients.get(data.storageUrl)
|
|
9
|
-
if (!client) {
|
|
9
|
+
if (!client && !clients.has(data.storageUrl)) {
|
|
10
10
|
try {
|
|
11
11
|
clients.set(data.storageUrl, client)
|
|
12
12
|
client = await MongoClient.connect(data.storageUrl, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
13
|
+
clients.set(data.storageUrl, client)
|
|
13
14
|
} catch (error) {
|
|
14
|
-
clients.delete(data.storageUrl)
|
|
15
15
|
console.error(`${data.organization_id}: storageName ${data.storageName} failed to connect to mongodb`)
|
|
16
16
|
errorHandler(data, error)
|
|
17
17
|
return { status: false }
|
|
@@ -43,7 +43,7 @@ function database(action, data) {
|
|
|
43
43
|
|
|
44
44
|
try {
|
|
45
45
|
const client = await dbClient(data)
|
|
46
|
-
if (client.status === false)
|
|
46
|
+
if (!client || client.status === false)
|
|
47
47
|
return data
|
|
48
48
|
if (action == 'readDatabase') {
|
|
49
49
|
const db = client.db().admin();
|
|
@@ -97,7 +97,7 @@ function array(action, data) {
|
|
|
97
97
|
|
|
98
98
|
try {
|
|
99
99
|
const client = await dbClient(data)
|
|
100
|
-
if (client.status === false)
|
|
100
|
+
if (!client || client.status === false)
|
|
101
101
|
return data
|
|
102
102
|
|
|
103
103
|
if (data.request)
|
|
@@ -243,7 +243,7 @@ function object(action, data) {
|
|
|
243
243
|
return new Promise(async (resolve, reject) => {
|
|
244
244
|
try {
|
|
245
245
|
const client = await dbClient(data)
|
|
246
|
-
if (client.status === false)
|
|
246
|
+
if (!client || client.status === false)
|
|
247
247
|
return data
|
|
248
248
|
|
|
249
249
|
let dataTransferedIn = 0
|