monsqlize 1.3.0 → 2.0.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.
Files changed (172) hide show
  1. package/CHANGELOG.md +56 -60
  2. package/LICENSE +201 -21
  3. package/README.md +537 -1828
  4. package/changelogs/README.md +160 -0
  5. package/changelogs/v2.0.0.md +222 -0
  6. package/dist/cjs/index.cjs +10600 -0
  7. package/dist/cjs/mongodb/common/transaction-aware.cjs +10 -0
  8. package/dist/cjs/transaction/CacheLockManager.cjs +100 -0
  9. package/dist/cjs/transaction/Transaction.cjs +158 -0
  10. package/dist/cjs/transaction/TransactionManager.cjs +298 -0
  11. package/dist/esm/index.mjs +10650 -0
  12. package/dist/types/base.d.ts +81 -0
  13. package/dist/types/collection.d.ts +1031 -0
  14. package/dist/types/expression.d.ts +115 -0
  15. package/dist/types/index.d.ts +23 -0
  16. package/dist/types/lock.d.ts +74 -0
  17. package/dist/types/model.d.ts +526 -0
  18. package/dist/types/mongodb.d.ts +49 -0
  19. package/dist/types/monsqlize.d.ts +491 -0
  20. package/dist/types/pool.d.ts +84 -0
  21. package/dist/types/runtime.d.ts +362 -0
  22. package/dist/types/saga.d.ts +143 -0
  23. package/dist/types/slow-query-log.d.ts +126 -0
  24. package/dist/types/sync.d.ts +103 -0
  25. package/dist/types/transaction.d.ts +132 -0
  26. package/package.json +67 -69
  27. package/index.d.ts +0 -206
  28. package/index.mjs +0 -52
  29. package/lib/cache-invalidation.js +0 -279
  30. package/lib/cache.js +0 -530
  31. package/lib/common/cursor.js +0 -59
  32. package/lib/common/docs-urls.js +0 -73
  33. package/lib/common/index-options.js +0 -223
  34. package/lib/common/log.js +0 -61
  35. package/lib/common/namespace.js +0 -22
  36. package/lib/common/normalize.js +0 -34
  37. package/lib/common/page-result.js +0 -43
  38. package/lib/common/runner.js +0 -57
  39. package/lib/common/server-features.js +0 -232
  40. package/lib/common/shape-builders.js +0 -27
  41. package/lib/common/validation.js +0 -113
  42. package/lib/connect.js +0 -99
  43. package/lib/constants.js +0 -55
  44. package/lib/count-queue.js +0 -188
  45. package/lib/distributed-cache-invalidator.js +0 -260
  46. package/lib/errors.js +0 -168
  47. package/lib/expression/cache/ExpressionCache.js +0 -114
  48. package/lib/expression/compiler/ExpressionCompiler.js +0 -1090
  49. package/lib/expression/compiler/ExpressionCompilerExtensions.js +0 -531
  50. package/lib/expression/detector.js +0 -84
  51. package/lib/expression/factory.js +0 -29
  52. package/lib/expression/index.js +0 -19
  53. package/lib/function-cache.js +0 -533
  54. package/lib/index.js +0 -1251
  55. package/lib/infrastructure/ConnectionPoolManager.js +0 -464
  56. package/lib/infrastructure/HealthChecker.js +0 -281
  57. package/lib/infrastructure/PoolConfig.js +0 -199
  58. package/lib/infrastructure/PoolSelector.js +0 -225
  59. package/lib/infrastructure/PoolStats.js +0 -244
  60. package/lib/infrastructure/ssh-tunnel-ssh2.js +0 -212
  61. package/lib/infrastructure/ssh-tunnel.js +0 -41
  62. package/lib/infrastructure/uri-parser.js +0 -36
  63. package/lib/lock/Lock.js +0 -67
  64. package/lib/lock/errors.js +0 -28
  65. package/lib/lock/index.js +0 -13
  66. package/lib/logger.js +0 -225
  67. package/lib/model/examples/test.js +0 -311
  68. package/lib/model/features/defaults.js +0 -161
  69. package/lib/model/features/populate.js +0 -568
  70. package/lib/model/features/relations.js +0 -120
  71. package/lib/model/features/soft-delete.js +0 -349
  72. package/lib/model/features/version.js +0 -157
  73. package/lib/model/features/virtuals.js +0 -219
  74. package/lib/model/index.js +0 -1265
  75. package/lib/mongodb/common/accessor-helpers.js +0 -59
  76. package/lib/mongodb/common/agg-pipeline.js +0 -36
  77. package/lib/mongodb/common/aggregation-validator.js +0 -127
  78. package/lib/mongodb/common/iid.js +0 -28
  79. package/lib/mongodb/common/lexicographic-expr.js +0 -53
  80. package/lib/mongodb/common/shape.js +0 -32
  81. package/lib/mongodb/common/sort.js +0 -39
  82. package/lib/mongodb/common/transaction-aware.js +0 -25
  83. package/lib/mongodb/connect.js +0 -234
  84. package/lib/mongodb/index.js +0 -639
  85. package/lib/mongodb/management/admin-ops.js +0 -200
  86. package/lib/mongodb/management/bookmark-ops.js +0 -167
  87. package/lib/mongodb/management/cache-ops.js +0 -50
  88. package/lib/mongodb/management/collection-ops.js +0 -387
  89. package/lib/mongodb/management/database-ops.js +0 -202
  90. package/lib/mongodb/management/index-ops.js +0 -475
  91. package/lib/mongodb/management/index.js +0 -17
  92. package/lib/mongodb/management/namespace.js +0 -31
  93. package/lib/mongodb/management/validation-ops.js +0 -268
  94. package/lib/mongodb/queries/aggregate.js +0 -172
  95. package/lib/mongodb/queries/chain.js +0 -631
  96. package/lib/mongodb/queries/count.js +0 -99
  97. package/lib/mongodb/queries/distinct.js +0 -78
  98. package/lib/mongodb/queries/find-and-count.js +0 -193
  99. package/lib/mongodb/queries/find-by-ids.js +0 -236
  100. package/lib/mongodb/queries/find-one-by-id.js +0 -171
  101. package/lib/mongodb/queries/find-one.js +0 -71
  102. package/lib/mongodb/queries/find-page.js +0 -618
  103. package/lib/mongodb/queries/find.js +0 -171
  104. package/lib/mongodb/queries/index.js +0 -51
  105. package/lib/mongodb/queries/watch.js +0 -538
  106. package/lib/mongodb/writes/common/batch-retry.js +0 -65
  107. package/lib/mongodb/writes/delete-batch.js +0 -323
  108. package/lib/mongodb/writes/delete-many.js +0 -181
  109. package/lib/mongodb/writes/delete-one.js +0 -173
  110. package/lib/mongodb/writes/find-one-and-delete.js +0 -203
  111. package/lib/mongodb/writes/find-one-and-replace.js +0 -239
  112. package/lib/mongodb/writes/find-one-and-update.js +0 -240
  113. package/lib/mongodb/writes/increment-one.js +0 -259
  114. package/lib/mongodb/writes/index.js +0 -46
  115. package/lib/mongodb/writes/insert-batch.js +0 -508
  116. package/lib/mongodb/writes/insert-many.js +0 -223
  117. package/lib/mongodb/writes/insert-one.js +0 -169
  118. package/lib/mongodb/writes/replace-one.js +0 -226
  119. package/lib/mongodb/writes/result-handler.js +0 -237
  120. package/lib/mongodb/writes/update-batch.js +0 -416
  121. package/lib/mongodb/writes/update-many.js +0 -275
  122. package/lib/mongodb/writes/update-one.js +0 -273
  123. package/lib/mongodb/writes/upsert-one.js +0 -203
  124. package/lib/multi-level-cache.js +0 -244
  125. package/lib/operators.js +0 -330
  126. package/lib/redis-cache-adapter.js +0 -267
  127. package/lib/saga/SagaContext.js +0 -67
  128. package/lib/saga/SagaDefinition.js +0 -32
  129. package/lib/saga/SagaExecutor.js +0 -201
  130. package/lib/saga/SagaOrchestrator.js +0 -186
  131. package/lib/saga/index.js +0 -11
  132. package/lib/slow-query-log/base-storage.js +0 -70
  133. package/lib/slow-query-log/batch-queue.js +0 -97
  134. package/lib/slow-query-log/config-manager.js +0 -196
  135. package/lib/slow-query-log/index.js +0 -238
  136. package/lib/slow-query-log/mongodb-storage.js +0 -324
  137. package/lib/slow-query-log/query-hash.js +0 -39
  138. package/lib/sync/ChangeStreamSyncManager.js +0 -405
  139. package/lib/sync/ResumeTokenStore.js +0 -192
  140. package/lib/sync/SyncConfig.js +0 -127
  141. package/lib/sync/SyncTarget.js +0 -240
  142. package/lib/sync/index.js +0 -20
  143. package/lib/transaction/CacheLockManager.js +0 -162
  144. package/lib/transaction/DistributedCacheLockManager.js +0 -475
  145. package/lib/transaction/Transaction.js +0 -315
  146. package/lib/transaction/TransactionManager.js +0 -267
  147. package/lib/transaction/index.js +0 -11
  148. package/lib/utils/objectid-converter.js +0 -632
  149. package/types/README.md +0 -122
  150. package/types/base.ts +0 -94
  151. package/types/batch.ts +0 -187
  152. package/types/cache.ts +0 -71
  153. package/types/chain.ts +0 -254
  154. package/types/collection.ts +0 -357
  155. package/types/expression.ts +0 -109
  156. package/types/function-cache.d.ts +0 -135
  157. package/types/lock.ts +0 -95
  158. package/types/model/definition.ts +0 -152
  159. package/types/model/index.ts +0 -10
  160. package/types/model/instance.ts +0 -121
  161. package/types/model/relations.ts +0 -121
  162. package/types/model/virtuals.ts +0 -32
  163. package/types/monsqlize.ts +0 -245
  164. package/types/options.ts +0 -192
  165. package/types/pagination.ts +0 -154
  166. package/types/pool.ts +0 -125
  167. package/types/query.ts +0 -71
  168. package/types/saga.ts +0 -125
  169. package/types/stream.ts +0 -64
  170. package/types/sync.ts +0 -79
  171. package/types/transaction.ts +0 -79
  172. package/types/write.ts +0 -77
@@ -1,268 +0,0 @@
1
- /**
2
- * 集合验证相关操作方法工厂函数
3
- * 提供 Schema 验证规则管理
4
- * @module mongodb/management/validation-ops
5
- */
6
-
7
- const { createValidationError } = require('../../errors');
8
-
9
- /**
10
- * 创建验证操作方法
11
- * @param {Object} context - 上下文对象
12
- * @param {Object} context.db - MongoDB 数据库实例
13
- * @param {Object} context.collection - MongoDB 集合实例
14
- * @param {Object} context.logger - 日志记录器
15
- * @returns {Object} 验证操作方法集合
16
- */
17
- function createValidationOps(context) {
18
- const { db, collection, logger } = context;
19
-
20
- return {
21
- /**
22
- * 设置集合的验证规则
23
- * @param {Object} validator - 验证规则(JSON Schema 或查询表达式)
24
- * @param {Object} [options] - 选项
25
- * @param {string} [options.validationLevel] - 验证级别
26
- * @param {string} [options.validationAction] - 验证失败时的行为
27
- * @returns {Promise<Object>} 设置结果
28
- *
29
- * @example
30
- * // 使用 JSON Schema 验证
31
- * await collection.setValidator({
32
- * $jsonSchema: {
33
- * bsonType: 'object',
34
- * required: ['name', 'email'],
35
- * properties: {
36
- * name: {
37
- * bsonType: 'string',
38
- * description: 'must be a string and is required'
39
- * },
40
- * email: {
41
- * bsonType: 'string',
42
- * pattern: '^.+@.+$',
43
- * description: 'must be a valid email'
44
- * },
45
- * age: {
46
- * bsonType: 'int',
47
- * minimum: 0,
48
- * maximum: 120,
49
- * description: 'must be an integer between 0 and 120'
50
- * }
51
- * }
52
- * }
53
- * });
54
- *
55
- * // 使用查询表达式验证
56
- * await collection.setValidator({
57
- * $and: [
58
- * { name: { $type: 'string' } },
59
- * { email: { $regex: /@/ } }
60
- * ]
61
- * });
62
- *
63
- * // 同时设置验证级别和行为
64
- * await collection.setValidator({
65
- * $jsonSchema: { /* ... * / }
66
- * }, {
67
- * validationLevel: 'moderate',
68
- * validationAction: 'warn'
69
- * });
70
- */
71
- async setValidator(validator, options = {}) {
72
- try {
73
- if (!validator || typeof validator !== 'object') {
74
- throw createValidationError(
75
- 'Validator must be an object',
76
- 'INVALID_VALIDATOR'
77
- );
78
- }
79
-
80
- const command = {
81
- collMod: collection.collectionName,
82
- validator
83
- };
84
-
85
- if (options.validationLevel) {
86
- command.validationLevel = options.validationLevel;
87
- }
88
-
89
- if (options.validationAction) {
90
- command.validationAction = options.validationAction;
91
- }
92
-
93
- const result = await db.command(command);
94
-
95
- logger.info('Validator set', {
96
- collection: collection.collectionName,
97
- validationLevel: options.validationLevel,
98
- validationAction: options.validationAction
99
- });
100
-
101
- return {
102
- ok: result.ok,
103
- collection: collection.collectionName,
104
- validator: 'set'
105
- };
106
- } catch (error) {
107
- logger.error('setValidator failed', { error: error.message });
108
- throw createValidationError(
109
- `Failed to set validator: ${error.message}`,
110
- 'SET_VALIDATOR_ERROR'
111
- );
112
- }
113
- },
114
-
115
- /**
116
- * 设置验证级别
117
- *
118
- * 验证级别:
119
- * - 'off': 禁用验证
120
- * - 'strict': 对所有插入和更新进行验证(默认)
121
- * - 'moderate': 只验证有效文档的更新,不验证现有无效文档
122
- *
123
- * @param {string} level - 验证级别('off'/'strict'/'moderate')
124
- * @returns {Promise<Object>} 设置结果
125
- *
126
- * @example
127
- * // 严格验证(所有文档)
128
- * await collection.setValidationLevel('strict');
129
- *
130
- * // 适度验证(只验证有效文档)
131
- * await collection.setValidationLevel('moderate');
132
- *
133
- * // 禁用验证
134
- * await collection.setValidationLevel('off');
135
- */
136
- async setValidationLevel(level) {
137
- try {
138
- const validLevels = ['off', 'strict', 'moderate'];
139
- if (!validLevels.includes(level)) {
140
- throw createValidationError(
141
- `Invalid validation level. Must be one of: ${validLevels.join(', ')}`,
142
- 'INVALID_VALIDATION_LEVEL'
143
- );
144
- }
145
-
146
- const result = await db.command({
147
- collMod: collection.collectionName,
148
- validationLevel: level
149
- });
150
-
151
- logger.info('Validation level set', {
152
- collection: collection.collectionName,
153
- level
154
- });
155
-
156
- return {
157
- ok: result.ok,
158
- collection: collection.collectionName,
159
- validationLevel: level
160
- };
161
- } catch (error) {
162
- logger.error('setValidationLevel failed', { error: error.message });
163
- throw createValidationError(
164
- `Failed to set validation level: ${error.message}`,
165
- 'SET_VALIDATION_LEVEL_ERROR'
166
- );
167
- }
168
- },
169
-
170
- /**
171
- * 设置验证失败时的行为
172
- *
173
- * 验证行为:
174
- * - 'error': 拒绝不符合规则的文档(默认)
175
- * - 'warn': 允许写入但记录警告
176
- *
177
- * @param {string} action - 验证行为('error'/'warn')
178
- * @returns {Promise<Object>} 设置结果
179
- *
180
- * @example
181
- * // 拒绝无效文档
182
- * await collection.setValidationAction('error');
183
- *
184
- * // 允许但警告
185
- * await collection.setValidationAction('warn');
186
- */
187
- async setValidationAction(action) {
188
- try {
189
- const validActions = ['error', 'warn'];
190
- if (!validActions.includes(action)) {
191
- throw createValidationError(
192
- `Invalid validation action. Must be one of: ${validActions.join(', ')}`,
193
- 'INVALID_VALIDATION_ACTION'
194
- );
195
- }
196
-
197
- const result = await db.command({
198
- collMod: collection.collectionName,
199
- validationAction: action
200
- });
201
-
202
- logger.info('Validation action set', {
203
- collection: collection.collectionName,
204
- action
205
- });
206
-
207
- return {
208
- ok: result.ok,
209
- collection: collection.collectionName,
210
- validationAction: action
211
- };
212
- } catch (error) {
213
- logger.error('setValidationAction failed', { error: error.message });
214
- throw createValidationError(
215
- `Failed to set validation action: ${error.message}`,
216
- 'SET_VALIDATION_ACTION_ERROR'
217
- );
218
- }
219
- },
220
-
221
- /**
222
- * 获取集合的验证规则
223
- * @returns {Promise<Object>} 验证规则信息
224
- * @property {Object} validator - 验证规则
225
- * @property {string} validationLevel - 验证级别
226
- * @property {string} validationAction - 验证行为
227
- *
228
- * @example
229
- * const validation = await collection.getValidator();
230
- * console.log('Validator:', validation.validator);
231
- * console.log('Level:', validation.validationLevel);
232
- * console.log('Action:', validation.validationAction);
233
- */
234
- async getValidator() {
235
- try {
236
- const collections = await db.listCollections({
237
- name: collection.collectionName
238
- }).toArray();
239
-
240
- if (collections.length === 0) {
241
- throw createValidationError(
242
- `Collection '${collection.collectionName}' not found`,
243
- 'COLLECTION_NOT_FOUND'
244
- );
245
- }
246
-
247
- const collInfo = collections[0];
248
- const options = collInfo.options || {};
249
-
250
- return {
251
- validator: options.validator || null,
252
- validationLevel: options.validationLevel || 'strict',
253
- validationAction: options.validationAction || 'error'
254
- };
255
- } catch (error) {
256
- logger.error('getValidator failed', { error: error.message });
257
- throw createValidationError(
258
- `Failed to get validator: ${error.message}`,
259
- 'GET_VALIDATOR_ERROR'
260
- );
261
- }
262
- }
263
- };
264
- }
265
-
266
- module.exports = { createValidationOps };
267
-
268
-
@@ -1,172 +0,0 @@
1
- /**
2
- * aggregate 查询模块
3
- * @description 提供 MongoDB 聚合管道功能,支持流式返回和缓存
4
- */
5
-
6
- const { AggregateChain } = require('./chain');
7
- const { convertAggregationPipeline } = require('../../utils/objectid-converter');
8
- const { hasExpressionInPipeline } = require('../../expression/detector');
9
- const ExpressionCompiler = require('../../expression/compiler/ExpressionCompiler');
10
-
11
- // 创建全局编译器实例(单例)
12
- let globalCompiler = null;
13
-
14
- function getCompiler(expressionConfig = {}) {
15
- if (!globalCompiler) {
16
- globalCompiler = new ExpressionCompiler(expressionConfig);
17
- }
18
- return globalCompiler;
19
- }
20
-
21
- /**
22
- * 创建 aggregate 查询操作
23
- * @param {Object} context - 上下文对象
24
- * @returns {Object} 包含 aggregate 方法的对象
25
- */
26
- function createAggregateOps(context) {
27
- const {
28
- collection,
29
- defaults,
30
- run,
31
- instanceId,
32
- effectiveDbName,
33
- logger,
34
- emit,
35
- mongoSlowLogShaper
36
- } = context;
37
-
38
- return {
39
- /**
40
- * 聚合查询(MongoDB 聚合管道透传)
41
- * @param {Array} pipeline - 聚合管道数组,如 [{ $match: {...} }, { $group: {...} }]
42
- * @param {Object} [options={}] - 聚合选项
43
- * @param {number} [options.cache=0] - 缓存时间(毫秒),默认不缓存(聚合通常动态性强)
44
- * @param {number} [options.maxTimeMS] - 查询超时时间(毫秒)
45
- * @param {boolean} [options.allowDiskUse=false] - 是否允许使用磁盘(默认 false)
46
- * @param {Object} [options.collation] - 排序规则(可选)
47
- * @param {string|Object} [options.hint] - 索引提示(可选)
48
- * @param {string} [options.comment] - 查询注释(可选)
49
- * @param {boolean|Object} [options.meta] - 是否返回耗时元信息
50
- * @param {boolean} [options.stream] - 是否返回流式结果
51
- * @param {number} [options.batchSize] - 批处理大小
52
- * @param {boolean|string} [options.explain] - 是否返回查询执行计划,可选值:true/'queryPlanner'/'executionStats'/'allPlansExecution'
53
- * @returns {Promise<Array>|ReadableStream|AggregateChain} 聚合结果数组或可读流(当 stream: true 时);当 explain=true 时返回执行计划;默认返回 AggregateChain 实例支持链式调用
54
- */
55
- aggregate: (pipeline = [], options = {}) => {
56
- // 🆕 v1.1.0: 检测并编译统一表达式
57
- let processedPipeline = pipeline;
58
-
59
- if (hasExpressionInPipeline(pipeline)) {
60
- const compiler = getCompiler(context.expressionConfig);
61
- processedPipeline = compiler.compilePipeline(pipeline, {
62
- targetDB: 'mongodb'
63
- });
64
-
65
- if (context.logger && context.expressionConfig?.debug) {
66
- context.logger.debug('[Expression] Pipeline compiled', {
67
- original: pipeline,
68
- compiled: processedPipeline
69
- });
70
- }
71
- }
72
-
73
- // ✅ v1.3.0: 自动转换聚合管道中的 ObjectId 字符串
74
- const convertedPipeline = convertAggregationPipeline(processedPipeline, 0, {
75
- logger: context.logger,
76
- excludeFields: context.autoConvertConfig?.excludeFields,
77
- customFieldPatterns: context.autoConvertConfig?.customFieldPatterns,
78
- maxDepth: context.autoConvertConfig?.maxDepth || 5
79
- });
80
-
81
- // 如果没有提供 options 或 options 为空对象,返回 AggregateChain 以支持完整的链式调用
82
- const hasOptions = options && Object.keys(options).length > 0;
83
-
84
- if (!hasOptions) {
85
- // 返回 AggregateChain 实例,支持 .hint().collation() 等链式调用
86
- return new AggregateChain(context, convertedPipeline, {});
87
- }
88
-
89
- // 如果提供了 options,执行原有逻辑(向后兼容)
90
- const {
91
- maxTimeMS = defaults.maxTimeMS,
92
- allowDiskUse = false,
93
- collation,
94
- hint,
95
- comment,
96
- stream = false,
97
- batchSize,
98
- explain
99
- } = options;
100
-
101
- // 构建 MongoDB 聚合选项
102
- const aggOptions = { maxTimeMS, allowDiskUse };
103
- if (collation) aggOptions.collation = collation;
104
- if (hint) aggOptions.hint = hint;
105
- if (comment) aggOptions.comment = comment;
106
- if (batchSize !== undefined) aggOptions.batchSize = batchSize;
107
-
108
- // 如果启用 explain,直接返回执行计划(不缓存)
109
- if (explain) {
110
- const verbosity = typeof explain === 'string' ? explain : 'queryPlanner';
111
- const cursor = collection.aggregate(convertedPipeline, aggOptions);
112
- return cursor.explain(verbosity);
113
- }
114
-
115
- // 如果启用流式返回,直接返回 MongoDB 游标流
116
- if (stream) {
117
- const cursor = collection.aggregate(convertedPipeline, aggOptions);
118
- const readableStream = cursor.stream();
119
-
120
- // 添加慢查询日志支持
121
- const startTime = Date.now();
122
- let docCount = 0;
123
-
124
- readableStream.on('data', () => {
125
- docCount++;
126
- });
127
-
128
- readableStream.on('end', () => {
129
- const durationMs = Date.now() - startTime;
130
- const slowQueryMs = defaults?.slowQueryMs || 500;
131
-
132
- if (durationMs >= slowQueryMs) {
133
- try {
134
- const meta = {
135
- op: 'aggregate-stream',
136
- durationMs,
137
- docCount,
138
- iid: instanceId,
139
- type: context.type,
140
- db: effectiveDbName,
141
- collection: collection.collectionName,
142
- pipeline: mongoSlowLogShaper?.sanitize ? mongoSlowLogShaper.sanitize(pipeline) : pipeline,
143
- };
144
- logger?.warn?.('🐌 Slow aggregate stream', meta);
145
- emit?.('slow-query', meta);
146
- } catch (_) { }
147
- }
148
- });
149
-
150
- return readableStream;
151
- }
152
-
153
- // 执行聚合的 Promise
154
- const resultPromise = run(
155
- 'aggregate',
156
- options,
157
- async () => collection.aggregate(convertedPipeline, aggOptions).toArray()
158
- );
159
-
160
- // 添加 explain 方法支持链式调用(与原生 MongoDB 一致)
161
- resultPromise.explain = async (verbosity = 'queryPlanner') => {
162
- const cursor = collection.aggregate(convertedPipeline, aggOptions);
163
- return cursor.explain(verbosity);
164
- };
165
-
166
- return resultPromise;
167
- }
168
- };
169
- }
170
-
171
- module.exports = createAggregateOps;
172
-