@cocreate/mongodb 1.2.0 → 1.2.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/CHANGELOG.md +16 -0
- package/CoCreate.config.js +1 -1
- package/package.json +1 -1
- package/src/index.js +18 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [1.2.2](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.2.1...v1.2.2) (2023-04-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* dbClient optimization ([1a18f6f](https://github.com/CoCreate-app/CoCreate-mongodb/commit/1a18f6f68cd9cd1f7546b36743aa164337d74423))
|
|
7
|
+
* renamed domans to hosts ([10d3f86](https://github.com/CoCreate-app/CoCreate-mongodb/commit/10d3f860d1f1f42beb008069a7282632e4c617aa))
|
|
8
|
+
* return platformClient if organization_id = process.env.organization_id ([a758d7f](https://github.com/CoCreate-app/CoCreate-mongodb/commit/a758d7f63c176edaf8f1c1033196e70b82d52168))
|
|
9
|
+
|
|
10
|
+
## [1.2.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.2.0...v1.2.1) (2023-03-28)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* data.filter && data.filter.query ([bc3a0db](https://github.com/CoCreate-app/CoCreate-mongodb/commit/bc3a0db6d1fb6e7eed68031ed76a6af4cfcb1576))
|
|
16
|
+
|
|
1
17
|
# [1.2.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.1.25...v1.2.0) (2023-03-19)
|
|
2
18
|
|
|
3
19
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,36 +2,22 @@ const { MongoClient, ObjectId } = require('mongodb');
|
|
|
2
2
|
const { dotNotationToObject, queryData, searchData, sortData } = require('@cocreate/utils')
|
|
3
3
|
const clients = new Map()
|
|
4
4
|
|
|
5
|
-
async function mongoClient(dbUrl) {
|
|
6
|
-
try {
|
|
7
|
-
dbUrl = dbUrl || process.env.MONGO_URL;
|
|
8
|
-
if (!dbUrl || !dbUrl.includes('mongodb'))
|
|
9
|
-
console.log('CoCreate.config.js missing dbUrl')
|
|
10
|
-
const Client = MongoClient.connect(dbUrl, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
11
|
-
return Client;
|
|
12
|
-
} catch (error) {
|
|
13
|
-
console.error(error)
|
|
14
|
-
return {
|
|
15
|
-
status: false
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let platformClient;
|
|
21
|
-
mongoClient().then(Client => {
|
|
22
|
-
platformClient = Client
|
|
23
|
-
});
|
|
24
5
|
|
|
25
6
|
async function dbClient(data) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
if (data.dbUrl) {
|
|
8
|
+
let client = clients.get(data.dbUrl)
|
|
9
|
+
if (!client) {
|
|
10
|
+
try {
|
|
11
|
+
client = MongoClient.connect(data.dbUrl, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
12
|
+
clients.set(data.dbUrl, client)
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error(error)
|
|
15
|
+
return { status: false }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return client
|
|
33
19
|
}
|
|
34
|
-
return
|
|
20
|
+
return
|
|
35
21
|
}
|
|
36
22
|
|
|
37
23
|
async function databaseStats(data) {
|
|
@@ -73,8 +59,11 @@ function database(action, data) {
|
|
|
73
59
|
db.listDatabases(function (err, dbs) {
|
|
74
60
|
|
|
75
61
|
for (let database of dbs.databases) {
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
if (data.filter && data.filter.query) {
|
|
63
|
+
let isFilter = queryData(database, data.filter.query)
|
|
64
|
+
if (isFilter)
|
|
65
|
+
databaseArray.push({ database, db: 'mongodb' })
|
|
66
|
+
} else
|
|
78
67
|
databaseArray.push({ database, db: 'mongodb' })
|
|
79
68
|
}
|
|
80
69
|
|