@cocreate/mongodb 1.3.1 → 1.4.0

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,17 @@
1
+ # [1.4.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.3.2...v1.4.0) (2023-05-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * Refactor index.js document function to return updated documents when returnDocument is set to false. ([6dba55b](https://github.com/CoCreate-app/CoCreate-mongodb/commit/6dba55b93237d7e411ddacb09be7242f103edc7f))
7
+
8
+ ## [1.3.2](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.3.1...v1.3.2) (2023-05-20)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * updated dependencies to their latest versions ([adca1c6](https://github.com/CoCreate-app/CoCreate-mongodb/commit/adca1c6046ae3ec00121df74072c46fbaf3082f3))
14
+
1
15
  ## [1.3.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.3.0...v1.3.1) (2023-05-19)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
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",
@@ -59,9 +59,9 @@
59
59
  "webpack-log": "^3.0.1"
60
60
  },
61
61
  "dependencies": {
62
- "@cocreate/docs": "^1.5.13",
63
- "@cocreate/hosting": "^1.7.13",
64
- "@cocreate/utils": "^1.18.2",
62
+ "@cocreate/docs": "^1.7.11",
63
+ "@cocreate/hosting": "^1.10.3",
64
+ "@cocreate/utils": "^1.20.9",
65
65
  "mongodb": "^4.12.1"
66
66
  }
67
67
  }
package/src/index.js CHANGED
@@ -397,6 +397,20 @@ function document(action, data) {
397
397
  doc.database = database
398
398
  doc.collection = collection
399
399
  doc._id = doc._id.toString()
400
+
401
+ if (data.returnDocument == false) {
402
+ let tempDoc = {};
403
+ let docs = new Map(data[type].map((obj) => [obj._id, obj]));
404
+ let doc1 = docs.get(doc._id)
405
+ if (doc1) {
406
+ tempDoc._id = tempDoc
407
+ for (let key of Object.keys(doc1)) {
408
+ tempDoc[key] = doc[key]
409
+ }
410
+ doc = tempDoc
411
+ }
412
+ }
413
+
400
414
  documents.push(doc)
401
415
  }
402
416
  }
@@ -404,18 +418,6 @@ function document(action, data) {
404
418
  if (index && limit) {
405
419
  documents = documents.slice(index, limit)
406
420
  }
407
-
408
- if (data.returnDocument == false) {
409
-
410
- for (let item of data['data']) {
411
- let resp = {};
412
- resp['_id'] = tmp['_id']
413
- data[type].forEach((f) => resp[f] = item[f])
414
- documents.push(resp);
415
- }
416
-
417
- data['data'] = documents
418
- }
419
421
  }
420
422
 
421
423
  collectionsLength -= 1