@dnax/core 0.73.3 → 0.73.4
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/driver/mongo/rest.ts +4 -2
- package/driver/mongo/utils.ts +5 -2
- package/package.json +1 -1
package/driver/mongo/rest.ts
CHANGED
|
@@ -1657,6 +1657,7 @@ class useRest {
|
|
|
1657
1657
|
collection: collection,
|
|
1658
1658
|
tenant_id: this.#tenant_id,
|
|
1659
1659
|
action: "updateMany",
|
|
1660
|
+
upsert: true,
|
|
1660
1661
|
}),
|
|
1661
1662
|
},
|
|
1662
1663
|
},
|
|
@@ -1813,15 +1814,16 @@ class useRest {
|
|
|
1813
1814
|
collection: collection,
|
|
1814
1815
|
tenant_id: this.#tenant_id,
|
|
1815
1816
|
}),
|
|
1817
|
+
|
|
1816
1818
|
$setOnInsert: {
|
|
1817
1819
|
...formatData(update?.$setOnInsert || {}, {
|
|
1818
1820
|
collection: collection,
|
|
1819
1821
|
tenant_id: this.#tenant_id,
|
|
1820
1822
|
action: "insertOne",
|
|
1823
|
+
upsert: true,
|
|
1821
1824
|
}),
|
|
1822
|
-
//updatedAt: new Date(),
|
|
1823
|
-
createdAt: new Date(),
|
|
1824
1825
|
},
|
|
1826
|
+
|
|
1825
1827
|
$currentDate: {
|
|
1826
1828
|
updatedAt: true,
|
|
1827
1829
|
},
|
package/driver/mongo/utils.ts
CHANGED
|
@@ -188,6 +188,7 @@ function transformAllDate(data: object) {
|
|
|
188
188
|
function toBson<T>(
|
|
189
189
|
data: object | T,
|
|
190
190
|
options?: {
|
|
191
|
+
upsert?: boolean;
|
|
191
192
|
action?:
|
|
192
193
|
| "insertOne"
|
|
193
194
|
| "insertMany"
|
|
@@ -204,14 +205,14 @@ function toBson<T>(
|
|
|
204
205
|
// InsertOne
|
|
205
206
|
if (options?.action == "insertOne") {
|
|
206
207
|
data.createdAt = new Date();
|
|
207
|
-
data.updatedAt = new Date();
|
|
208
|
+
if (!options?.upsert) data.updatedAt = new Date();
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
// insertMany
|
|
211
212
|
if (options?.action == "insertMany" && Array.isArray(data)) {
|
|
212
213
|
data?.map((d) => {
|
|
213
214
|
d.createdAt = new Date();
|
|
214
|
-
d.updatedAt = new Date();
|
|
215
|
+
if (!options?.upsert) d.updatedAt = new Date();
|
|
215
216
|
});
|
|
216
217
|
}
|
|
217
218
|
|
|
@@ -414,6 +415,7 @@ function formatData(
|
|
|
414
415
|
collection?: string;
|
|
415
416
|
action?: Actions;
|
|
416
417
|
tenant_id: string;
|
|
418
|
+
upsert?: boolean;
|
|
417
419
|
} = {
|
|
418
420
|
tenant_id: "_",
|
|
419
421
|
collection: "",
|
|
@@ -424,6 +426,7 @@ function formatData(
|
|
|
424
426
|
data = deepSetId(col, data);
|
|
425
427
|
}
|
|
426
428
|
data = toBson(data, {
|
|
429
|
+
upsert: options?.upsert,
|
|
427
430
|
action: options?.action,
|
|
428
431
|
});
|
|
429
432
|
|