w-orm-mongodb 1.2.6 → 1.2.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.
@@ -83,7 +83,7 @@ opt.autoGenPk為false時套件一律不產生id,未帶有效id者以reject拋
83
83
 
84
84
  <dt class="tag-source">Source:</dt>
85
85
  <dd class="tag-source"><ul class="dummy"><li>
86
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line39">line 39</a>
86
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line40">line 40</a>
87
87
  </li></ul></dd>
88
88
 
89
89
 
@@ -474,7 +474,7 @@ opt.autoGenPk為false時套件一律不產生id,未帶有效id者以reject拋
474
474
 
475
475
  <dt class="tag-source">Source:</dt>
476
476
  <dd class="tag-source"><ul class="dummy"><li>
477
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line980">line 980</a>
477
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1000">line 1000</a>
478
478
  </li></ul></dd>
479
479
 
480
480
 
@@ -629,14 +629,31 @@ opt.autoGenPk為false時套件一律不產生id,未帶有效id者以reject拋
629
629
  <dl class="details">
630
630
 
631
631
  <dt class="tag-description">Description:</dt>
632
- <dd class="tag-description"><ul class="dummy"><li><p>刪除全部數據,需與del分開,避免未傳數據導致直接刪除全表
633
- 註: n為實際刪除筆數,恆等於nDeleted;條件無命中時回傳0亦屬正常結果</p></li></ul></dd>
632
+ <dd class="tag-description"><ul class="dummy"><li><p>依條件刪除多筆數據(破壞性操作,須審慎使用,非必要不用;刪除單筆請用del),需與del分開,避免未傳數據導致直接刪除全表</p>
633
+ <p>使用須知:</p>
634
+ <ol>
635
+ <li>不給條件即刪除全部數據:find未給、為undefined或為{}時,刪除資料表內全部數據,不另行確認。給了條件才是部分刪除。</li>
636
+ <li>傳了值卻不是條件物件(null、陣列含[]與[{...}]、字串、數值、布林、函數、Date、RegExp、Map、Set、類別實例等),
637
+ 一律整批reject,不視為{},不刪除任何數據。</li>
638
+ <li>條件僅支援系列白名單:欄位等值{欄:純量}(多欄為AND)、欄位運算子$eq $ne $gt $gte $lt $lte(值為純量)與
639
+ $in $nin(值為純量陣列)、文件層$and $or(值為條件物件之非空陣列,最多1000項)。純量為字串、有限數字、布林、有效Date;
640
+ null僅可用於欄位等值、$eq、$ne。白名單外之運算子($not $nor $regex $options $exists $where $expr $text等)、
641
+ 欄位層$and/$or、點路徑、函數值、Symbol鍵、undefined值、空的$nin/$and/$or等一律整批reject,
642
+ 訊息為invalid find: 原因 at [路徑],且不連線、不刪除任何數據。</li>
643
+ <li>與select共用同一檢核與同一條件,select(find)命中之數據即本函數刪除之數據;
644
+ 建議先以select(find)確認命中範圍再刪除。</li>
645
+ <li>條件值若來自可能為undefined、null或空陣列之變數,呼叫端須先自行判斷;undefined值會reject而非被忽略,
646
+ 空的$nin會reject,$in:[]則為恆假(刪除0筆)。</li>
647
+ <li>語意差異(MongoDB式,依伺服器原生行為,見README):$ne(比較值非null)與$nin會命中欄位為null或缺欄之數據,$ne:null則僅命中欄位存在且非null者。
648
+ 需明確表達時可用可攜寫法:排除null為{$and:[{f:{$ne:null}},{f:{$ne:x}}]},含null為{$or:[{f:null},{f:{$ne:x}}]}。</li>
649
+ </ol>
650
+ <p>註: n為實際刪除筆數,恆等於nDeleted;條件無命中時回傳0亦屬正常結果</p></li></ul></dd>
634
651
 
635
652
 
636
653
 
637
654
  <dt class="tag-source">Source:</dt>
638
655
  <dd class="tag-source"><ul class="dummy"><li>
639
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1108">line 1108</a>
656
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1145">line 1145</a>
640
657
  </li></ul></dd>
641
658
 
642
659
 
@@ -745,7 +762,7 @@ opt.autoGenPk為false時套件一律不產生id,未帶有效id者以reject拋
745
762
  </td>
746
763
 
747
764
 
748
- <td class="description last"><p>輸入刪除條件物件</p></td>
765
+ <td class="description last"><p>輸入刪除條件物件(系列白名單,規則見使用須知),不給予find則代表刪除全部數據</p></td>
749
766
  </tr>
750
767
 
751
768
 
@@ -808,15 +825,29 @@ opt.autoGenPk為false時套件一律不產生id,未帶有效id者以reject拋
808
825
  <dl class="details">
809
826
 
810
827
  <dt class="tag-description">Description:</dt>
811
- <dd class="tag-description"><ul class="dummy"><li><p>使用GridFS,刪除全部數據,需與delGfs分開,避免未傳數據導致直接刪除全部
812
- 註: n為實際刪除筆數,恆等於nDeleted;條件無命中時回傳0亦屬正常結果
828
+ <dd class="tag-description"><ul class="dummy"><li><p>使用GridFS,依條件刪除多筆數據(破壞性操作,須審慎使用,非必要不用;刪除單筆請用delGfs),需與delGfs分開,避免未傳數據導致直接刪除全部</p>
829
+ <p>使用須知:</p>
830
+ <ol>
831
+ <li>不給條件即刪除全部數據:find未給、為undefined或為{}時,刪除全部檔案,不另行確認。給了條件才是部分刪除。</li>
832
+ <li>傳了值卻不是條件物件(null、陣列含[]與[{...}]、字串、數值、布林、函數、Date、RegExp、Map、Set、類別實例等),
833
+ 一律整批reject,不視為{},不刪除任何數據。</li>
834
+ <li>條件僅支援系列白名單,規則與delAll相同,條件作用於GridFS之<cl>.files文件(欄位如filename、length、uploadDate):
835
+ 欄位等值{欄:純量}(多欄為AND)、欄位運算子$eq $ne $gt $gte $lt $lte(值為純量)與$in $nin(值為純量陣列)、
836
+ 文件層$and $or(值為條件物件之非空陣列,最多1000項)。白名單外之運算子($not $nor $regex $options $exists $where $expr $text等)、
837
+ 欄位層$and/$or、點路徑(如metadata.*)、函數值、Symbol鍵、undefined值、空的$nin/$and/$or等一律整批reject,
838
+ 訊息為invalid find: 原因 at [路徑],且不連線、不刪除任何數據。</li>
839
+ <li>條件值若來自可能為undefined、null或空陣列之變數,呼叫端須先自行判斷;undefined值會reject而非被忽略,
840
+ 空的$nin會reject,$in:[]則為恆假(刪除0筆)。</li>
841
+ <li>語意差異(MongoDB式,依伺服器原生行為):$ne(比較值非null)與$nin會命中欄位為null或缺欄之數據,$ne:null則僅命中欄位存在且非null者。</li>
842
+ </ol>
843
+ <p>註: n為實際刪除筆數,恆等於nDeleted;條件無命中時回傳0亦屬正常結果
813
844
  本函數不建立唯一索引,以免既有數據尚存重複id時無法清除</p></li></ul></dd>
814
845
 
815
846
 
816
847
 
817
848
  <dt class="tag-source">Source:</dt>
818
849
  <dd class="tag-source"><ul class="dummy"><li>
819
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1562">line 1562</a>
850
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1632">line 1632</a>
820
851
  </li></ul></dd>
821
852
 
822
853
 
@@ -925,7 +956,7 @@ opt.autoGenPk為false時套件一律不產生id,未帶有效id者以reject拋
925
956
  </td>
926
957
 
927
958
 
928
- <td class="description last"><p>輸入刪除條件物件</p></td>
959
+ <td class="description last"><p>輸入刪除條件物件(系列白名單,規則見使用須知),不給予find則代表刪除全部數據</p></td>
929
960
  </tr>
930
961
 
931
962
 
@@ -990,13 +1021,14 @@ opt.autoGenPk為false時套件一律不產生id,未帶有效id者以reject拋
990
1021
  <dt class="tag-description">Description:</dt>
991
1022
  <dd class="tag-description"><ul class="dummy"><li><p>使用GridFS,刪除數據
992
1023
  註: n為id命中筆數;未帶有效id者視為本筆無法處理,以ok為0並附err回報;
1024
+ id含NUL或孤立代理字元者不符系列條件白名單,尚未查找即以ok為0、n為0並附err(invalid find: ...)回報,不影響同批其他筆;
993
1025
  判斷本筆是否真的被刪除一律以nDeleted為準</p></li></ul></dd>
994
1026
 
995
1027
 
996
1028
 
997
1029
  <dt class="tag-source">Source:</dt>
998
1030
  <dd class="tag-source"><ul class="dummy"><li>
999
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1418">line 1418</a>
1031
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1471">line 1471</a>
1000
1032
  </li></ul></dd>
1001
1033
 
1002
1034
 
@@ -1162,7 +1194,7 @@ opt.autoGenPk為false時套件一律不產生id,未帶有效id者以reject拋
1162
1194
 
1163
1195
  <dt class="tag-source">Source:</dt>
1164
1196
  <dd class="tag-source"><ul class="dummy"><li>
1165
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line432">line 432</a>
1197
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line452">line 452</a>
1166
1198
  </li></ul></dd>
1167
1199
 
1168
1200
 
@@ -1456,7 +1488,7 @@ standalone無交易可用而以補償動作達成,其限制詳見_insertBulkBy
1456
1488
 
1457
1489
  <dt class="tag-source">Source:</dt>
1458
1490
  <dd class="tag-source"><ul class="dummy"><li>
1459
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line682">line 682</a>
1491
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line702">line 702</a>
1460
1492
  </li></ul></dd>
1461
1493
 
1462
1494
 
@@ -1620,7 +1652,7 @@ standalone無交易可用而以補償動作達成,其限制詳見_insertBulkBy
1620
1652
 
1621
1653
  <dt class="tag-source">Source:</dt>
1622
1654
  <dd class="tag-source"><ul class="dummy"><li>
1623
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1172">line 1172</a>
1655
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1220">line 1220</a>
1624
1656
  </li></ul></dd>
1625
1657
 
1626
1658
 
@@ -1784,7 +1816,7 @@ standalone無交易可用而以補償動作達成,其限制詳見_insertBulkBy
1784
1816
 
1785
1817
  <dt class="tag-source">Source:</dt>
1786
1818
  <dd class="tag-source"><ul class="dummy"><li>
1787
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line900">line 900</a>
1819
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line920">line 920</a>
1788
1820
  </li></ul></dd>
1789
1821
 
1790
1822
 
@@ -2065,13 +2097,20 @@ standalone無交易可用而以補償動作達成,其限制詳見_insertBulkBy
2065
2097
  <dl class="details">
2066
2098
 
2067
2099
  <dt class="tag-description">Description:</dt>
2068
- <dd class="tag-description"><ul class="dummy"><li><p>查詢數據</p></li></ul></dd>
2100
+ <dd class="tag-description"><ul class="dummy"><li><p>查詢數據</p>
2101
+ <p>條件(find)僅支援系列白名單,規則同delAll之第1-3點,詳見README之條件(find)白名單:
2102
+ 欄位等值{欄:純量}(多欄為AND)、欄位運算子$eq $ne $gt $gte $lt $lte(值為純量)與$in $nin(值為純量陣列)、
2103
+ 文件層$and $or(值為條件物件之非空陣列);未給、undefined或{}回傳全部數據;
2104
+ 非條件物件或白名單外之輸入(如$regex $where $exists $not $nor、點路徑、undefined值、函數值)整批reject,
2105
+ 訊息為invalid find: 原因 at [路徑],且不連線、不讀取。
2106
+ 語意差異(MongoDB式):$ne(比較值非null)與$nin會命中欄位為null或缺欄之數據,$ne:null則僅命中欄位存在且非null者,需明確表達時可用可攜寫法,
2107
+ 排除null為{$and:[{f:{$ne:null}},{f:{$ne:x}}]},含null為{$or:[{f:null},{f:{$ne:x}}]}。</p></li></ul></dd>
2069
2108
 
2070
2109
 
2071
2110
 
2072
2111
  <dt class="tag-source">Source:</dt>
2073
2112
  <dd class="tag-source"><ul class="dummy"><li>
2074
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line307">line 307</a>
2113
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line316">line 316</a>
2075
2114
  </li></ul></dd>
2076
2115
 
2077
2116
 
@@ -2180,7 +2219,7 @@ standalone無交易可用而以補償動作達成,其限制詳見_insertBulkBy
2180
2219
  </td>
2181
2220
 
2182
2221
 
2183
- <td class="description last"><p>輸入查詢條件物件</p></td>
2222
+ <td class="description last"><p>輸入查詢條件物件(系列白名單,規則同delAll之第1-3點),未給、undefined或{}回傳全部數據,非條件物件或白名單外運算子整批reject</p></td>
2184
2223
  </tr>
2185
2224
 
2186
2225
 
@@ -2251,7 +2290,7 @@ standalone無交易可用而以補償動作達成,其限制詳見_insertBulkBy
2251
2290
 
2252
2291
  <dt class="tag-source">Source:</dt>
2253
2292
  <dd class="tag-source"><ul class="dummy"><li>
2254
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line364">line 364</a>
2293
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line384">line 384</a>
2255
2294
  </li></ul></dd>
2256
2295
 
2257
2296
 
@@ -2412,7 +2451,7 @@ standalone無交易可用而以補償動作達成,其限制詳見_insertBulkBy
2412
2451
 
2413
2452
  <dt class="tag-source">Source:</dt>
2414
2453
  <dd class="tag-source"><ul class="dummy"><li>
2415
- <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1282">line 1282</a>
2454
+ <a href="WOrmMongodb.mjs.html">WOrmMongodb.mjs</a>, <a href="WOrmMongodb.mjs.html#line1330">line 1330</a>
2416
2455
  </li></ul></dd>
2417
2456
 
2418
2457
 
@@ -2569,7 +2608,7 @@ standalone無交易可用而以補償動作達成,其限制詳見_insertBulkBy
2569
2608
  <br class="clear">
2570
2609
 
2571
2610
  <footer>
2572
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Oct 11 2026 13:55:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2611
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Oct 17 2026 14:13:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2573
2612
  </footer>
2574
2613
 
2575
2614
  <script>prettyPrint();</script>
@@ -55,6 +55,7 @@ import get from 'lodash-es/get.js'
55
55
  import map from 'lodash-es/map.js'
56
56
  import omit from 'lodash-es/omit.js'
57
57
  import size from 'lodash-es/size.js'
58
+ import cvOrmFind from 'wsemi/src/cvOrmFind.mjs'
58
59
  import evem from 'wsemi/src/evem.mjs'
59
60
  import genPm from 'wsemi/src/genPm.mjs'
60
61
  import genIDSeq from 'wsemi/src/genIDSeq.mjs'
@@ -347,20 +348,34 @@ function WOrmMongodb(opt = {}) {
347
348
  /**
348
349
  * 查詢數據
349
350
  *
351
+ * 條件(find)僅支援系列白名單,規則同delAll之第1-3點,詳見README之條件(find)白名單:
352
+ * 欄位等值{欄:純量}(多欄為AND)、欄位運算子$eq $ne $gt $gte $lt $lte(值為純量)與$in $nin(值為純量陣列)、
353
+ * 文件層$and $or(值為條件物件之非空陣列);未給、undefined或{}回傳全部數據;
354
+ * 非條件物件或白名單外之輸入(如$regex $where $exists $not $nor、點路徑、undefined值、函數值)整批reject,
355
+ * 訊息為invalid find: 原因 at [路徑],且不連線、不讀取。
356
+ * 語意差異(MongoDB式):$ne(比較值非null)與$nin會命中欄位為null或缺欄之數據,$ne:null則僅命中欄位存在且非null者,需明確表達時可用可攜寫法,
357
+ * 排除null為{$and:[{f:{$ne:null}},{f:{$ne:x}}]},含null為{$or:[{f:null},{f:{$ne:x}}]}。
358
+ *
350
359
  * @memberOf WOrmMongodb
351
- * @param {Object} [find={}] 輸入查詢條件物件
360
+ * @param {Object} [find={}] 輸入查詢條件物件(系列白名單,規則同delAll之第1-3點),未給、undefined或{}回傳全部數據,非條件物件或白名單外運算子整批reject
352
361
  * @returns {Promise} 回傳Promise,resolve回傳數據陣列,無符合數據回傳空陣列,reject回傳錯誤訊息
353
362
  */
354
363
  async function select(find = {}) {
355
364
  let isErr = false
356
365
 
357
366
  //client
358
- let client = new MongoClient(opt.url)
367
+ let client = null
359
368
 
360
369
  //res
361
370
  let res = null
362
371
  try {
363
372
 
373
+ //cvOrmFind, 須先於建立client與任何讀取, 不合白名單者往外拋(整批性錯誤), 其後一律只用檢核後之複本(檢查之值即使用之值)
374
+ find = cvOrmFind(find)
375
+
376
+ //client
377
+ client = new MongoClient(opt.url)
378
+
364
379
  //database, collection
365
380
  let database = client.db(opt.db)
366
381
  let collection = database.collection(opt.cl)
@@ -383,8 +398,13 @@ function WOrmMongodb(opt = {}) {
383
398
  res = err
384
399
  }
385
400
  finally {
386
- await client.close()
387
- client = null
401
+
402
+ //client, 條件檢核失敗時尚未建立
403
+ if (client !== null) {
404
+ await client.close()
405
+ client = null
406
+ }
407
+
388
408
  }
389
409
 
390
410
  //check
@@ -1145,23 +1165,46 @@ function WOrmMongodb(opt = {}) {
1145
1165
 
1146
1166
 
1147
1167
  /**
1148
- * 刪除全部數據,需與del分開,避免未傳數據導致直接刪除全表
1168
+ * 依條件刪除多筆數據(破壞性操作,須審慎使用,非必要不用;刪除單筆請用del),需與del分開,避免未傳數據導致直接刪除全表
1169
+ *
1170
+ * 使用須知:
1171
+ * 1. 不給條件即刪除全部數據:find未給、為undefined或為{}時,刪除資料表內全部數據,不另行確認。給了條件才是部分刪除。
1172
+ * 2. 傳了值卻不是條件物件(null、陣列含[]與[{...}]、字串、數值、布林、函數、Date、RegExp、Map、Set、類別實例等),
1173
+ * 一律整批reject,不視為{},不刪除任何數據。
1174
+ * 3. 條件僅支援系列白名單:欄位等值{欄:純量}(多欄為AND)、欄位運算子$eq $ne $gt $gte $lt $lte(值為純量)與
1175
+ * $in $nin(值為純量陣列)、文件層$and $or(值為條件物件之非空陣列,最多1000項)。純量為字串、有限數字、布林、有效Date;
1176
+ * null僅可用於欄位等值、$eq、$ne。白名單外之運算子($not $nor $regex $options $exists $where $expr $text等)、
1177
+ * 欄位層$and/$or、點路徑、函數值、Symbol鍵、undefined值、空的$nin/$and/$or等一律整批reject,
1178
+ * 訊息為invalid find: 原因 at [路徑],且不連線、不刪除任何數據。
1179
+ * 4. 與select共用同一檢核與同一條件,select(find)命中之數據即本函數刪除之數據;
1180
+ * 建議先以select(find)確認命中範圍再刪除。
1181
+ * 5. 條件值若來自可能為undefined、null或空陣列之變數,呼叫端須先自行判斷;undefined值會reject而非被忽略,
1182
+ * 空的$nin會reject,$in:[]則為恆假(刪除0筆)。
1183
+ * 6. 語意差異(MongoDB式,依伺服器原生行為,見README):$ne(比較值非null)與$nin會命中欄位為null或缺欄之數據,$ne:null則僅命中欄位存在且非null者。
1184
+ * 需明確表達時可用可攜寫法:排除null為{$and:[{f:{$ne:null}},{f:{$ne:x}}]},含null為{$or:[{f:null},{f:{$ne:x}}]}。
1185
+ *
1149
1186
  * 註: n為實際刪除筆數,恆等於nDeleted;條件無命中時回傳0亦屬正常結果
1150
1187
  *
1151
1188
  * @memberOf WOrmMongodb
1152
- * @param {Object} [find={}] 輸入刪除條件物件
1189
+ * @param {Object} [find={}] 輸入刪除條件物件(系列白名單,規則見使用須知),不給予find則代表刪除全部數據
1153
1190
  * @returns {Promise} 回傳Promise,resolve回傳刪除結果,reject回傳錯誤訊息
1154
1191
  */
1155
1192
  async function delAll(find = {}) {
1156
1193
  let isErr = false
1157
1194
 
1158
1195
  //client
1159
- let client = new MongoClient(opt.url)
1196
+ let client = null
1160
1197
 
1161
1198
  //res
1162
1199
  let res = null
1163
1200
  try {
1164
1201
 
1202
+ //cvOrmFind, 須先於建立client與任何刪除, 不合白名單者往外拋(整批性錯誤), 其後一律只用檢核後之複本(檢查之值即使用之值), 複本無自有鍵代表全部
1203
+ find = cvOrmFind(find)
1204
+
1205
+ //client
1206
+ client = new MongoClient(opt.url)
1207
+
1165
1208
  //database, collection
1166
1209
  let database = client.db(opt.db)
1167
1210
  let collection = database.collection(opt.cl)
@@ -1185,8 +1228,13 @@ function WOrmMongodb(opt = {}) {
1185
1228
  res = err
1186
1229
  }
1187
1230
  finally {
1188
- await client.close()
1189
- client = null
1231
+
1232
+ //client, 條件檢核失敗時尚未建立
1233
+ if (client !== null) {
1234
+ await client.close()
1235
+ client = null
1236
+ }
1237
+
1190
1238
  }
1191
1239
 
1192
1240
  //emit
@@ -1427,6 +1475,7 @@ function WOrmMongodb(opt = {}) {
1427
1475
 
1428
1476
 
1429
1477
  //_findGfs, 內部查找函數, 其reject由delGfs與delAllGfs之catch接住並於該處發出error事件, 故本函數不自行發出
1478
+ //註: bucket.find之唯一入口, 條件(find)須符合系列白名單, 故於查找前再經cvOrmFind(對delAllGfs已檢核之複本為冪等), delGfs逐筆之{ filename: id }亦經此
1430
1479
  async function _findGfs(find = {}, bucket) {
1431
1480
  let isErr = false
1432
1481
 
@@ -1434,6 +1483,9 @@ function WOrmMongodb(opt = {}) {
1434
1483
  let res = null
1435
1484
  try {
1436
1485
 
1486
+ //cvOrmFind, 不合白名單者往外拋, 其後只用檢核後之複本
1487
+ find = cvOrmFind(find)
1488
+
1437
1489
  //find
1438
1490
  let cursor = bucket.find(find)
1439
1491
 
@@ -1456,6 +1508,7 @@ function WOrmMongodb(opt = {}) {
1456
1508
  /**
1457
1509
  * 使用GridFS,刪除數據
1458
1510
  * 註: n為id命中筆數;未帶有效id者視為本筆無法處理,以ok為0並附err回報;
1511
+ * id含NUL或孤立代理字元者不符系列條件白名單,尚未查找即以ok為0、n為0並附err(invalid find: ...)回報,不影響同批其他筆;
1459
1512
  * 判斷本筆是否真的被刪除一律以nDeleted為準
1460
1513
  *
1461
1514
  * @memberOf WOrmMongodb
@@ -1542,12 +1595,15 @@ function WOrmMongodb(opt = {}) {
1542
1595
 
1543
1596
  //本筆失敗不中斷整批
1544
1597
 
1545
- //rest
1598
+ //errMsg
1599
+ let errMsg = getErrMsg(err)
1600
+
1601
+ //rest, 條件未通過白名單檢核者(id含NUL或孤立代理字元)尚未查找, 視同無效id而n為0, 其餘為查找或刪除途中失敗, 本筆已嘗試而n為1
1546
1602
  rest = {
1547
- n: 1,
1603
+ n: errMsg.indexOf('invalid find: ') === 0 ? 0 : 1,
1548
1604
  nDeleted: 0,
1549
1605
  ok: 0,
1550
- err: getErrMsg(err),
1606
+ err: errMsg,
1551
1607
  }
1552
1608
 
1553
1609
  }
@@ -1598,24 +1654,44 @@ function WOrmMongodb(opt = {}) {
1598
1654
 
1599
1655
 
1600
1656
  /**
1601
- * 使用GridFS,刪除全部數據,需與delGfs分開,避免未傳數據導致直接刪除全部
1657
+ * 使用GridFS,依條件刪除多筆數據(破壞性操作,須審慎使用,非必要不用;刪除單筆請用delGfs),需與delGfs分開,避免未傳數據導致直接刪除全部
1658
+ *
1659
+ * 使用須知:
1660
+ * 1. 不給條件即刪除全部數據:find未給、為undefined或為{}時,刪除全部檔案,不另行確認。給了條件才是部分刪除。
1661
+ * 2. 傳了值卻不是條件物件(null、陣列含[]與[{...}]、字串、數值、布林、函數、Date、RegExp、Map、Set、類別實例等),
1662
+ * 一律整批reject,不視為{},不刪除任何數據。
1663
+ * 3. 條件僅支援系列白名單,規則與delAll相同,條件作用於GridFS之&lt;cl>.files文件(欄位如filename、length、uploadDate):
1664
+ * 欄位等值{欄:純量}(多欄為AND)、欄位運算子$eq $ne $gt $gte $lt $lte(值為純量)與$in $nin(值為純量陣列)、
1665
+ * 文件層$and $or(值為條件物件之非空陣列,最多1000項)。白名單外之運算子($not $nor $regex $options $exists $where $expr $text等)、
1666
+ * 欄位層$and/$or、點路徑(如metadata.*)、函數值、Symbol鍵、undefined值、空的$nin/$and/$or等一律整批reject,
1667
+ * 訊息為invalid find: 原因 at [路徑],且不連線、不刪除任何數據。
1668
+ * 4. 條件值若來自可能為undefined、null或空陣列之變數,呼叫端須先自行判斷;undefined值會reject而非被忽略,
1669
+ * 空的$nin會reject,$in:[]則為恆假(刪除0筆)。
1670
+ * 5. 語意差異(MongoDB式,依伺服器原生行為):$ne(比較值非null)與$nin會命中欄位為null或缺欄之數據,$ne:null則僅命中欄位存在且非null者。
1671
+ *
1602
1672
  * 註: n為實際刪除筆數,恆等於nDeleted;條件無命中時回傳0亦屬正常結果
1603
1673
  * 本函數不建立唯一索引,以免既有數據尚存重複id時無法清除
1604
1674
  *
1605
1675
  * @memberOf WOrmMongodb
1606
- * @param {Object} [find={}] 輸入刪除條件物件
1676
+ * @param {Object} [find={}] 輸入刪除條件物件(系列白名單,規則見使用須知),不給予find則代表刪除全部數據
1607
1677
  * @returns {Promise} 回傳Promise,resolve回傳刪除結果,reject回傳錯誤訊息
1608
1678
  */
1609
1679
  async function delAllGfs(find = {}) {
1610
1680
  let isErr = false
1611
1681
 
1612
1682
  //client
1613
- let client = new MongoClient(opt.url)
1683
+ let client = null
1614
1684
 
1615
1685
  //res
1616
1686
  let res = null
1617
1687
  try {
1618
1688
 
1689
+ //cvOrmFind, 須先於建立client與任何刪除, 不合白名單者往外拋(整批性錯誤), 其後一律只用檢核後之複本(檢查之值即使用之值), 複本無自有鍵代表全部
1690
+ find = cvOrmFind(find)
1691
+
1692
+ //client
1693
+ client = new MongoClient(opt.url)
1694
+
1619
1695
  //database
1620
1696
  let database = client.db(opt.db)
1621
1697
 
@@ -1653,8 +1729,13 @@ function WOrmMongodb(opt = {}) {
1653
1729
  res = err
1654
1730
  }
1655
1731
  finally {
1656
- await client.close()
1657
- client = null
1732
+
1733
+ //client, 條件檢核失敗時尚未建立
1734
+ if (client !== null) {
1735
+ await client.close()
1736
+ client = null
1737
+ }
1738
+
1658
1739
  }
1659
1740
 
1660
1741
  //emit
@@ -1707,7 +1788,7 @@ export default WOrmMongodb
1707
1788
  <br class="clear">
1708
1789
 
1709
1790
  <footer>
1710
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Oct 11 2026 13:55:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1791
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Oct 17 2026 14:13:30 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1711
1792
  </footer>
1712
1793
 
1713
1794
  <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.5</a> on Sun Oct 11 2026 13:55:32 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.5</a> on Sat Oct 17 2026 14:13:30 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
@@ -104,8 +104,10 @@ async function test() {
104
104
  let spc = await wo.select({ '$or': [{ '$and': [{ value: { '$ne': 123 } }, { value: { '$in': [123, 321, 123.456, 456] } }, { value: { '$nin': [456, 654] } }] }, { '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 400 } }] }] })
105
105
  console.log('select by $or, $and, $ne, $in, $nin', spc)
106
106
 
107
- //select by regex, $options之合法flag僅有i、m、x、s
108
- let sr = await wo.select({ name: { $regex: 'PeT', $options: 'i' } })
107
+ //select by regex, $regex與$options不在條件(find)白名單內(會reject), 需要模糊比對時改為select後於記憶體過濾
108
+ let sr = ss.filter(function(v) {
109
+ return /PeT/i.test(v.name)
110
+ })
109
111
  console.log('selectReg', sr)
110
112
 
111
113
  //selectByPk, 由id直接查找單筆, 不需如select提取全部符合數據再處理
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "w-orm-mongodb",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "main": "dist/w-orm-mongodb.umd.js",
5
5
  "dependencies": {
6
6
  "mongodb": "^7.5.0",
7
- "wsemi": "^1.9.12"
7
+ "wsemi": "^1.9.19"
8
8
  },
9
9
  "devDependencies": {
10
10
  "w-package-tools": "^1.1.16"