@cocreate/mongodb
Advanced tools
Comparing version
@@ -0,1 +1,8 @@ | ||
# [1.4.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.3.2...v1.4.0) (2023-05-21) | ||
### Features | ||
* 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)) | ||
## [1.3.2](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.3.1...v1.3.2) (2023-05-20) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@cocreate/mongodb", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"description": "A simple mongodb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -400,2 +400,16 @@ const { MongoClient, ObjectId } = require('mongodb'); | ||
doc._id = doc._id.toString() | ||
if (data.returnDocument == false) { | ||
let tempDoc = {}; | ||
let docs = new Map(data[type].map((obj) => [obj._id, obj])); | ||
let doc1 = docs.get(doc._id) | ||
if (doc1) { | ||
tempDoc._id = tempDoc | ||
for (let key of Object.keys(doc1)) { | ||
tempDoc[key] = doc[key] | ||
} | ||
doc = tempDoc | ||
} | ||
} | ||
documents.push(doc) | ||
@@ -408,14 +422,2 @@ } | ||
} | ||
if (data.returnDocument == false) { | ||
for (let item of data['data']) { | ||
let resp = {}; | ||
resp['_id'] = tmp['_id'] | ||
data[type].forEach((f) => resp[f] = item[f]) | ||
documents.push(resp); | ||
} | ||
data['data'] = documents | ||
} | ||
} | ||
@@ -422,0 +424,0 @@ |
65289
0.92%780
0.39%