w-orm-mongodb 1.1.31 → 1.1.32

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.
@@ -80,7 +80,7 @@
80
80
 
81
81
  <dt class="tag-source">Source:</dt>
82
82
  <dd class="tag-source"><ul class="dummy"><li>
83
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line32">line 32</a>
83
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line33">line 33</a>
84
84
  </li></ul></dd>
85
85
 
86
86
 
@@ -429,7 +429,7 @@
429
429
 
430
430
  <dt class="tag-source">Source:</dt>
431
431
  <dd class="tag-source"><ul class="dummy"><li>
432
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line331">line 331</a>
432
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line284">line 284</a>
433
433
  </li></ul></dd>
434
434
 
435
435
 
@@ -590,7 +590,7 @@
590
590
 
591
591
  <dt class="tag-source">Source:</dt>
592
592
  <dd class="tag-source"><ul class="dummy"><li>
593
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line400">line 400</a>
593
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line353">line 353</a>
594
594
  </li></ul></dd>
595
595
 
596
596
 
@@ -768,7 +768,7 @@
768
768
 
769
769
  <dt class="tag-source">Source:</dt>
770
770
  <dd class="tag-source"><ul class="dummy"><li>
771
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line758">line 758</a>
771
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line711">line 711</a>
772
772
  </li></ul></dd>
773
773
 
774
774
 
@@ -946,7 +946,7 @@
946
946
 
947
947
  <dt class="tag-source">Source:</dt>
948
948
  <dd class="tag-source"><ul class="dummy"><li>
949
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line651">line 651</a>
949
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line604">line 604</a>
950
950
  </li></ul></dd>
951
951
 
952
952
 
@@ -1104,7 +1104,7 @@
1104
1104
 
1105
1105
  <dt class="tag-source">Source:</dt>
1106
1106
  <dd class="tag-source"><ul class="dummy"><li>
1107
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line115">line 115</a>
1107
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line116">line 116</a>
1108
1108
  </li></ul></dd>
1109
1109
 
1110
1110
 
@@ -1265,7 +1265,7 @@
1265
1265
 
1266
1266
  <dt class="tag-source">Source:</dt>
1267
1267
  <dd class="tag-source"><ul class="dummy"><li>
1268
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line452">line 452</a>
1268
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line405">line 405</a>
1269
1269
  </li></ul></dd>
1270
1270
 
1271
1271
 
@@ -1638,46 +1638,6 @@
1638
1638
  </tr>
1639
1639
 
1640
1640
 
1641
-
1642
- <tr>
1643
-
1644
- <td class="name"><code>atomic</code></td>
1645
-
1646
-
1647
- <td class="type">
1648
-
1649
-
1650
- <span class="param-type">boolean</span>
1651
-
1652
-
1653
-
1654
-
1655
- </td>
1656
-
1657
-
1658
- <td class="attributes">
1659
-
1660
- &lt;optional><br>
1661
-
1662
-
1663
-
1664
-
1665
-
1666
- </td>
1667
-
1668
-
1669
-
1670
- <td class="default">
1671
-
1672
- <code>false</code>
1673
-
1674
- </td>
1675
-
1676
-
1677
- <td class="description last"><p>輸入是否於儲存時採用上鎖,避免同時操作互改問題,預設為false</p></td>
1678
- </tr>
1679
-
1680
-
1681
1641
  </tbody>
1682
1642
  </table>
1683
1643
 
@@ -1750,7 +1710,7 @@
1750
1710
 
1751
1711
  <dt class="tag-source">Source:</dt>
1752
1712
  <dd class="tag-source"><ul class="dummy"><li>
1753
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line62">line 62</a>
1713
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line63">line 63</a>
1754
1714
  </li></ul></dd>
1755
1715
 
1756
1716
 
@@ -1928,7 +1888,7 @@
1928
1888
 
1929
1889
  <dt class="tag-source">Source:</dt>
1930
1890
  <dd class="tag-source"><ul class="dummy"><li>
1931
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line539">line 539</a>
1891
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line492">line 492</a>
1932
1892
  </li></ul></dd>
1933
1893
 
1934
1894
 
@@ -2085,7 +2045,7 @@
2085
2045
  <br class="clear">
2086
2046
 
2087
2047
  <footer>
2088
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 24 2024 21:44:00 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2048
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Apr 07 2024 21:30:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2089
2049
  </footer>
2090
2050
 
2091
2051
  <script>prettyPrint();</script>
@@ -56,6 +56,7 @@ import size from 'lodash-es/size.js'
56
56
  import genPm from 'wsemi/src/genPm.mjs'
57
57
  import genID from 'wsemi/src/genID.mjs'
58
58
  import isarr from 'wsemi/src/isarr.mjs'
59
+ import iseobj from 'wsemi/src/iseobj.mjs'
59
60
  import pmSeries from 'wsemi/src/pmSeries.mjs'
60
61
 
61
62
 
@@ -239,7 +240,6 @@ function WOrmMongodb(opt = {}) {
239
240
  * @param {Object|Array} data 輸入數據物件或陣列
240
241
  * @param {Object} [option={}] 輸入設定物件,預設為{}
241
242
  * @param {boolean} [option.autoInsert=true] 輸入是否於儲存時發現原本無數據,則自動改以插入處理,預設為true
242
- * @param {boolean} [option.atomic=false] 輸入是否於儲存時採用上鎖,避免同時操作互改問題,預設為false
243
243
  * @returns {Promise} 回傳Promise,resolve回傳儲存結果,reject回傳錯誤訊息
244
244
  */
245
245
  async function save(data, option = {}) {
@@ -248,9 +248,8 @@ function WOrmMongodb(opt = {}) {
248
248
  //cloneDeep
249
249
  data = cloneDeep(data)
250
250
 
251
- //autoInsert, atomic
251
+ //autoInsert
252
252
  let autoInsert = get(option, 'autoInsert', true)
253
- let atomic = get(option, 'atomic', false)
254
253
 
255
254
  //client
256
255
  // let client = await MongoClient.connect(opt.url, optMGConn)
@@ -270,16 +269,6 @@ function WOrmMongodb(opt = {}) {
270
269
  data = [data]
271
270
  }
272
271
 
273
- //oper
274
- let oper = null
275
- if (atomic) {
276
- oper = 'findOneAndUpdate'
277
- }
278
- else {
279
- oper = 'updateOne'
280
- }
281
- // console.log('oper', oper)
282
-
283
272
  //pmSeries
284
273
  res = await pmSeries(data, async(v) => {
285
274
 
@@ -287,16 +276,10 @@ function WOrmMongodb(opt = {}) {
287
276
  let rest = null
288
277
 
289
278
  //oper
290
- rest = await collection[oper]({ id: v.id }, { $set: v })
279
+ rest = await collection.findOneAndUpdate({ id: v.id }, { $set: v })
291
280
  // console.log('rest', rest)
292
281
 
293
- if (rest) {
294
- // rest {
295
- // _id: new ObjectId('66002783fdb8a009c825f716'),
296
- // id: 'id-peter',
297
- // name: 'peter',
298
- // value: 123
299
- // }
282
+ if (iseobj(rest)) {
300
283
  rest = {
301
284
  n: 1,
302
285
  nModified: 1,
@@ -311,36 +294,6 @@ function WOrmMongodb(opt = {}) {
311
294
  }
312
295
  }
313
296
 
314
- // //check
315
- // if (get(rest, 'lastErrorObject')) { //findOneAndUpdate
316
- // // console.log('rest.lastErrorObject', rest.lastErrorObject)
317
- // rest = {
318
- // // lastErrorObject: { n: 1, updatedExisting: true },
319
- // // value: {
320
- // // _id: new ObjectId("615c18bb6e5db9935b10d88e"),
321
- // // id: 'id-rosemary',
322
- // // name: 'rosemary',
323
- // // value: 123.456
324
- // // },
325
- // // ok: 1
326
- // n: get(rest, 'lastErrorObject.n', -1),
327
- // nModified: get(rest, 'lastErrorObject.updatedExisting', false) ? 1 : 0,
328
- // ok: 1,
329
- // }
330
- // }
331
- // else { //updateOne
332
- // rest = {
333
- // // acknowledged: true,
334
- // // modifiedCount: 1,
335
- // // upsertedId: null,
336
- // // upsertedCount: 0,
337
- // // matchedCount: 1
338
- // n: get(rest, 'matchedCount', -1),
339
- // nModified: get(rest, 'modifiedCount', -1),
340
- // ok: get(rest, 'acknowledged', false) ? 1 : 0,
341
- // }
342
- // }
343
-
344
297
  //autoInsert
345
298
  if (autoInsert &amp;&amp; rest.n === 0) {
346
299
  rest = await insert(v)
@@ -894,7 +847,7 @@ export default WOrmMongodb
894
847
  <br class="clear">
895
848
 
896
849
  <footer>
897
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 24 2024 21:44:00 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
850
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Apr 07 2024 21:30:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
898
851
  </footer>
899
852
 
900
853
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -71,7 +71,7 @@
71
71
  <br class="clear">
72
72
 
73
73
  <footer>
74
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Mar 24 2024 21:44:00 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
74
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Sun Apr 07 2024 21:30:47 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
75
75
  </footer>
76
76
 
77
77
  <script>prettyPrint();</script>
package/g-basic.mjs CHANGED
@@ -75,7 +75,7 @@ async function test() {
75
75
 
76
76
 
77
77
  //save
78
- await w.save(rsm, { autoInsert: false, atomic: true })
78
+ await w.save(rsm, { autoInsert: false })
79
79
  .then(function(msg) {
80
80
  console.log('save then', msg)
81
81
  })
@@ -173,4 +173,4 @@ test()
173
173
  // change del
174
174
  // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
175
175
 
176
- //node --experimental-modules --es-module-specifier-resolution=node g-basic.mjs
176
+ //node --experimental-modules g-basic.mjs
package/g-gfs.mjs CHANGED
@@ -109,4 +109,4 @@ test()
109
109
  // change delGfs
110
110
  // delGfs { n: 1, nDeleted: 1, ok: 1 }
111
111
 
112
- //node --experimental-modules --es-module-specifier-resolution=node g-gfs.mjs
112
+ //node --experimental-modules g-gfs.mjs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w-orm-mongodb",
3
- "version": "1.1.31",
3
+ "version": "1.1.32",
4
4
  "main": "dist/w-orm-mongodb.umd.js",
5
5
  "dependencies": {
6
6
  "mongodb": "^6.5.0",
@@ -9,6 +9,7 @@ import size from 'lodash-es/size.js'
9
9
  import genPm from 'wsemi/src/genPm.mjs'
10
10
  import genID from 'wsemi/src/genID.mjs'
11
11
  import isarr from 'wsemi/src/isarr.mjs'
12
+ import iseobj from 'wsemi/src/iseobj.mjs'
12
13
  import pmSeries from 'wsemi/src/pmSeries.mjs'
13
14
 
14
15
 
@@ -192,7 +193,6 @@ function WOrmMongodb(opt = {}) {
192
193
  * @param {Object|Array} data 輸入數據物件或陣列
193
194
  * @param {Object} [option={}] 輸入設定物件,預設為{}
194
195
  * @param {boolean} [option.autoInsert=true] 輸入是否於儲存時發現原本無數據,則自動改以插入處理,預設為true
195
- * @param {boolean} [option.atomic=false] 輸入是否於儲存時採用上鎖,避免同時操作互改問題,預設為false
196
196
  * @returns {Promise} 回傳Promise,resolve回傳儲存結果,reject回傳錯誤訊息
197
197
  */
198
198
  async function save(data, option = {}) {
@@ -201,9 +201,8 @@ function WOrmMongodb(opt = {}) {
201
201
  //cloneDeep
202
202
  data = cloneDeep(data)
203
203
 
204
- //autoInsert, atomic
204
+ //autoInsert
205
205
  let autoInsert = get(option, 'autoInsert', true)
206
- let atomic = get(option, 'atomic', false)
207
206
 
208
207
  //client
209
208
  // let client = await MongoClient.connect(opt.url, optMGConn)
@@ -223,16 +222,6 @@ function WOrmMongodb(opt = {}) {
223
222
  data = [data]
224
223
  }
225
224
 
226
- //oper
227
- let oper = null
228
- if (atomic) {
229
- oper = 'findOneAndUpdate'
230
- }
231
- else {
232
- oper = 'updateOne'
233
- }
234
- // console.log('oper', oper)
235
-
236
225
  //pmSeries
237
226
  res = await pmSeries(data, async(v) => {
238
227
 
@@ -240,16 +229,10 @@ function WOrmMongodb(opt = {}) {
240
229
  let rest = null
241
230
 
242
231
  //oper
243
- rest = await collection[oper]({ id: v.id }, { $set: v })
232
+ rest = await collection.findOneAndUpdate({ id: v.id }, { $set: v })
244
233
  // console.log('rest', rest)
245
234
 
246
- if (rest) {
247
- // rest {
248
- // _id: new ObjectId('66002783fdb8a009c825f716'),
249
- // id: 'id-peter',
250
- // name: 'peter',
251
- // value: 123
252
- // }
235
+ if (iseobj(rest)) {
253
236
  rest = {
254
237
  n: 1,
255
238
  nModified: 1,
@@ -264,36 +247,6 @@ function WOrmMongodb(opt = {}) {
264
247
  }
265
248
  }
266
249
 
267
- // //check
268
- // if (get(rest, 'lastErrorObject')) { //findOneAndUpdate
269
- // // console.log('rest.lastErrorObject', rest.lastErrorObject)
270
- // rest = {
271
- // // lastErrorObject: { n: 1, updatedExisting: true },
272
- // // value: {
273
- // // _id: new ObjectId("615c18bb6e5db9935b10d88e"),
274
- // // id: 'id-rosemary',
275
- // // name: 'rosemary',
276
- // // value: 123.456
277
- // // },
278
- // // ok: 1
279
- // n: get(rest, 'lastErrorObject.n', -1),
280
- // nModified: get(rest, 'lastErrorObject.updatedExisting', false) ? 1 : 0,
281
- // ok: 1,
282
- // }
283
- // }
284
- // else { //updateOne
285
- // rest = {
286
- // // acknowledged: true,
287
- // // modifiedCount: 1,
288
- // // upsertedId: null,
289
- // // upsertedCount: 0,
290
- // // matchedCount: 1
291
- // n: get(rest, 'matchedCount', -1),
292
- // nModified: get(rest, 'modifiedCount', -1),
293
- // ok: get(rest, 'acknowledged', false) ? 1 : 0,
294
- // }
295
- // }
296
-
297
250
  //autoInsert
298
251
  if (autoInsert && rest.n === 0) {
299
252
  rest = await insert(v)