@cocreate/mongodb 1.18.5 → 1.18.7
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 +14 -0
- package/package.json +1 -1
- package/src/index.js +24 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.18.7](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.18.6...v1.18.7) (2024-07-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* remove new keyword from ObjectId ([8198e98](https://github.com/CoCreate-app/CoCreate-mongodb/commit/8198e98a7b297607f0a4b171256c7166b9675836))
|
|
7
|
+
|
|
8
|
+
## [1.18.6](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.18.5...v1.18.6) (2024-07-03)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* handling objectId in queries ([58c92b2](https://github.com/CoCreate-app/CoCreate-mongodb/commit/58c92b259da510e8020ff9211c72ce678905aceb))
|
|
14
|
+
|
|
1
15
|
## [1.18.5](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.18.4...v1.18.5) (2024-07-01)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -338,7 +338,7 @@ function object(method, data) {
|
|
|
338
338
|
if (data[type][i]._id || method === 'create') {
|
|
339
339
|
if (method !== 'create') {
|
|
340
340
|
try {
|
|
341
|
-
query._id =
|
|
341
|
+
query._id = ObjectId(data[type][i]._id);
|
|
342
342
|
} catch (error) {
|
|
343
343
|
if (method === 'update' && options.upsert) {
|
|
344
344
|
data[type][i]._id = ObjectId()
|
|
@@ -369,7 +369,8 @@ function object(method, data) {
|
|
|
369
369
|
// documents.push({ ...data[type][i], ...reference })
|
|
370
370
|
} else if (method === 'read') {
|
|
371
371
|
result = await arrayObj.findOne(query, projection);
|
|
372
|
-
|
|
372
|
+
if (result)
|
|
373
|
+
result._id = result._id.toString()
|
|
373
374
|
|
|
374
375
|
if (data[type][i].$storage && data[type][i].modified && data[type][i].modified.on) {
|
|
375
376
|
if (!result) {
|
|
@@ -381,8 +382,12 @@ function object(method, data) {
|
|
|
381
382
|
result = await arrayObj.updateOne(query, update, options);
|
|
382
383
|
} else
|
|
383
384
|
data[type][i] = { ...data[type][i], ...result }
|
|
384
|
-
} else
|
|
385
|
+
} else if (result)
|
|
385
386
|
data[type][i] = { ...data[type][i], ...result }
|
|
387
|
+
else {
|
|
388
|
+
data[type].splice(i, 1);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
386
391
|
} else if (method === 'update') {
|
|
387
392
|
result = await arrayObj.updateOne(query, update, options);
|
|
388
393
|
|
|
@@ -652,10 +657,16 @@ async function createFilter(data, arrayObj) {
|
|
|
652
657
|
if (typeof condition[subKey] === 'object' && condition[subKey] !== null) {
|
|
653
658
|
newCondition[subKey] = {};
|
|
654
659
|
for (let subCondition in condition[subKey]) {
|
|
655
|
-
|
|
660
|
+
if (subKey == "_id")
|
|
661
|
+
newCondition[subKey][subCondition] = ObjectId(condition[subKey][subCondition])
|
|
662
|
+
else
|
|
663
|
+
newCondition[subKey][subCondition] = convertIfDate(condition[subKey][subCondition]);
|
|
656
664
|
}
|
|
657
665
|
} else {
|
|
658
|
-
|
|
666
|
+
if (subKey == "_id")
|
|
667
|
+
newCondition[subKey] = ObjectId(condition[subKey])
|
|
668
|
+
else
|
|
669
|
+
newCondition[subKey] = convertIfDate(condition[subKey]);
|
|
659
670
|
}
|
|
660
671
|
}
|
|
661
672
|
return newCondition;
|
|
@@ -664,11 +675,17 @@ async function createFilter(data, arrayObj) {
|
|
|
664
675
|
// Handle general object conditions
|
|
665
676
|
query[key] = {};
|
|
666
677
|
for (let condition in data.$filter.query[key]) {
|
|
667
|
-
|
|
678
|
+
if (key == "_id")
|
|
679
|
+
query[key][condition] = ObjectId(data.$filter.query[key][condition])
|
|
680
|
+
else
|
|
681
|
+
query[key][condition] = convertIfDate(data.$filter.query[key][condition]);
|
|
668
682
|
}
|
|
669
683
|
} else {
|
|
670
684
|
// Handle direct values
|
|
671
|
-
|
|
685
|
+
if (key == "_id")
|
|
686
|
+
query[key] = ObjectId(data.$filter.query[key])
|
|
687
|
+
else
|
|
688
|
+
query[key] = convertIfDate(data.$filter.query[key]);
|
|
672
689
|
}
|
|
673
690
|
}
|
|
674
691
|
}
|