@cocreate/mongodb 1.2.1 → 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 CHANGED
@@ -1,3 +1,12 @@
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
+
1
10
  ## [1.2.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.2.0...v1.2.1) (2023-03-28)
2
11
 
3
12
 
@@ -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.2",
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) {