@cocreate/mongodb 1.2.1 → 1.2.3

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 CHANGED
@@ -1,3 +1,19 @@
1
+ ## [1.2.3](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.2.2...v1.2.3) (2023-04-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * data.filter.query error solved using if condition ([ab65717](https://github.com/CoCreate-app/CoCreate-mongodb/commit/ab65717ac77d900860b88c6a258a80e5d06194e9))
7
+
8
+ ## [1.2.2](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.2.1...v1.2.2) (2023-04-11)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * dbClient optimization ([1a18f6f](https://github.com/CoCreate-app/CoCreate-mongodb/commit/1a18f6f68cd9cd1f7546b36743aa164337d74423))
14
+ * renamed domans to hosts ([10d3f86](https://github.com/CoCreate-app/CoCreate-mongodb/commit/10d3f860d1f1f42beb008069a7282632e4c617aa))
15
+ * return platformClient if organization_id = process.env.organization_id ([a758d7f](https://github.com/CoCreate-app/CoCreate-mongodb/commit/a758d7f63c176edaf8f1c1033196e70b82d52168))
16
+
1
17
  ## [1.2.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.2.0...v1.2.1) (2023-03-28)
2
18
 
3
19
 
@@ -12,7 +12,7 @@ module.exports = {
12
12
  "name": "index.html",
13
13
  "path": "/docs/mongodb/index.html",
14
14
  "src": "{{./docs/index.html}}",
15
- "domains": [
15
+ "hosts": [
16
16
  "cocreate.app",
17
17
  "general.cocreate.app"
18
18
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "A simple mongodb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "mongodb",
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
- // ToDo: provide platform client only to specific collections ['permissions', 'metrics', 'organizations', 'users']
27
- if (!data.dbs)
28
- return platformClient
29
- let client = clients.get(data.dbs)
30
- if (!client) {
31
- client = await mongoClient(data.dbs)
32
- clients.set(data.dbs, client)
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 client
20
+ return
35
21
  }
36
22
 
37
23
  async function databaseStats(data) {
@@ -148,8 +134,11 @@ function collection(action, data) {
148
134
 
149
135
  if (result) {
150
136
  for (let res of result) {
151
- let isFilter = queryData(res, data.filter.query)
152
- if (isFilter)
137
+ if (data.filter && data.filter.query) {
138
+ let isFilter = queryData(res, data.filter.query)
139
+ if (isFilter)
140
+ collectionArray.push({ name: res.name, database, db: 'mongodb' })
141
+ } else
153
142
  collectionArray.push({ name: res.name, database, db: 'mongodb' })
154
143
  }
155
144
  }