@cocreate/mongodb 1.18.6 → 1.19.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.19.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.18.7...v1.19.0) (2024-11-02)
2
+
3
+
4
+ ### Features
5
+
6
+ * allowDiskUse, set $storage, $database, $array if not included ([39a71d9](https://github.com/CoCreate-app/CoCreate-mongodb/commit/39a71d9c29b6432dae1951fcad1ce88e3fbe817e))
7
+
8
+ ## [1.18.7](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.18.6...v1.18.7) (2024-07-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove new keyword from ObjectId ([8198e98](https://github.com/CoCreate-app/CoCreate-mongodb/commit/8198e98a7b297607f0a4b171256c7166b9675836))
14
+
1
15
  ## [1.18.6](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.18.5...v1.18.6) (2024-07-03)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.18.6",
3
+ "version": "1.19.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",
package/src/index.js CHANGED
@@ -302,9 +302,12 @@ function object(method, data) {
302
302
  if (!Array.isArray($array))
303
303
  $array = [data[type][i].$array]
304
304
 
305
- $storage.push(data.storageName)
306
- $database.push(database)
307
- $array.push(array)
305
+ if (!$storage.includes(data.storageName))
306
+ $storage.push(data.storageName)
307
+ if (!$database.includes(database))
308
+ $database.push(database)
309
+ if (!$array.includes(array))
310
+ $array.push(array)
308
311
 
309
312
  delete data[type][i].$storage
310
313
  delete data[type][i].$database
@@ -338,7 +341,7 @@ function object(method, data) {
338
341
  if (data[type][i]._id || method === 'create') {
339
342
  if (method !== 'create') {
340
343
  try {
341
- query._id = new ObjectId(data[type][i]._id);
344
+ query._id = ObjectId(data[type][i]._id);
342
345
  } catch (error) {
343
346
  if (method === 'update' && options.upsert) {
344
347
  data[type][i]._id = ObjectId()
@@ -369,7 +372,8 @@ function object(method, data) {
369
372
  // documents.push({ ...data[type][i], ...reference })
370
373
  } else if (method === 'read') {
371
374
  result = await arrayObj.findOne(query, projection);
372
- result._id = result._id.toString()
375
+ if (result)
376
+ result._id = result._id.toString()
373
377
 
374
378
  if (data[type][i].$storage && data[type][i].modified && data[type][i].modified.on) {
375
379
  if (!result) {
@@ -381,8 +385,12 @@ function object(method, data) {
381
385
  result = await arrayObj.updateOne(query, update, options);
382
386
  } else
383
387
  data[type][i] = { ...data[type][i], ...result }
384
- } else
388
+ } else if (result)
385
389
  data[type][i] = { ...data[type][i], ...result }
390
+ else {
391
+ data[type].splice(i, 1);
392
+ continue;
393
+ }
386
394
  } else if (method === 'update') {
387
395
  result = await arrayObj.updateOne(query, update, options);
388
396
 
@@ -417,8 +425,12 @@ function object(method, data) {
417
425
 
418
426
  dataTransferedOut += getBytes({ query, projection, sort, index, limit })
419
427
 
420
- let document = ''
421
- const cursor = arrayObj.find(query, projection).sort(sort).skip(index).limit(limit);
428
+ let cursor, document = ''
429
+ if (Object.keys(sort).length > 0)
430
+ cursor = arrayObj.find(query, projection).sort(sort).skip(index).limit(limit).allowDiskUse(true);
431
+ else
432
+ cursor = arrayObj.find(query, projection).sort(sort).skip(index).limit(limit);
433
+
422
434
  if (!(await cursor.hasNext()) && method === 'update' && data.upsert)
423
435
  document = { _id: ObjectId(data[type][i]._id) }
424
436