Skip to content

Commit b21b353

Browse files
committed
fix:代码中与实际文档不一致问题
1 parent 24d5ef5 commit b21b353

12 files changed

Lines changed: 580 additions & 114 deletions

File tree

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@
44

55
## 特性
66

7-
-**MongoDB 适配器**:完整支持 MongoDB 查询功能
8-
-**内置缓存**:TTL/LRU/命名空间失效/并发去重
9-
-**跨库访问**:轻松访问不同数据库的集合
10-
-**性能优化**:慢查询日志、查询超时控制
11-
-**类型安全**:完整的 TypeScript 类型声明
7+
### 🔵 MongoDB 原生功能支持
8+
9+
monSQLize 完整封装了 MongoDB 的原生功能:
10+
11+
-**标准查询方法**:find/findOne/aggregate/count/distinct
12+
-**链式调用 API**:完整支持 MongoDB 游标的所有链式方法
13+
-**所有查询选项**:projection/sort/limit/skip/hint/collation 等
14+
15+
### 🔧 monSQLize 扩展功能
16+
17+
在 MongoDB 原生功能基础上,提供额外的便利性和性能优化:
18+
19+
- 🔧 **智能缓存**:TTL/LRU/命名空间失效/并发去重
20+
- 🔧 **深度分页**:游标分页(支持前后翻页、跳页、书签)
21+
- 🔧 **性能监控**:慢查询日志、查询超时控制、元数据返回
22+
- 🔧 **跨库访问**:轻松访问不同数据库的集合
23+
- 🔧 **类型安全**:完整的 TypeScript 类型声明
24+
25+
**📚 详细对比**: 查看 [MongoDB 原生 vs monSQLize 扩展](./docs/mongodb-native-vs-extensions.md)
1226

1327
## 状态
1428

docs/aggregate.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,26 @@ async aggregate(pipeline = [], options = {})
3434

3535
### options 对象属性
3636

37-
| 参数 | 类型 | 必填 | 默认值 | 说明 |
38-
|------|------|------|--------|------|
39-
| `maxTimeMS` | Number || 全局配置 | 查询超时时间(毫秒) |
40-
| `allowDiskUse` | Boolean || `false` | 是否允许使用磁盘(处理大数据集时) |
41-
| `collation` | Object || - | 字符串排序规则 |
42-
| `hint` | Object/String || - | 指定使用的索引 |
43-
| `comment` | String || - | 查询注释(用于日志和分析) |
44-
| `stream` | Boolean || `false` | 是否返回流对象 |
45-
| `batchSize` | Number || - | 流式查询或数组查询时的批次大小 |
46-
| `explain` | Boolean/String || - | 返回查询执行计划 |
37+
| 参数 | 类型 | 必填 | 默认值 | 来源 | 说明 |
38+
|------|------|------|--------|------|------|
39+
| `maxTimeMS` | Number || 全局配置 | MongoDB 原生 ✅ | 查询超时时间(毫秒) |
40+
| `allowDiskUse` | Boolean || `false` | MongoDB 原生 ✅ | 是否允许使用磁盘(处理大数据集时) |
41+
| `collation` | Object || - | MongoDB 原生 ✅ | 字符串排序规则 |
42+
| `hint` | Object/String || - | MongoDB 原生 ✅ | 指定使用的索引 |
43+
| `comment` | String || - | MongoDB 原生 ✅ | 查询注释(用于日志和分析) |
44+
| `batchSize` | Number || - | MongoDB 原生 ✅ | 流式查询或数组查询时的批次大小 |
45+
| `explain` | Boolean/String || - | MongoDB 原生 ✅ | 返回查询执行计划 |
46+
| `stream` | Boolean || `false` | monSQLize 扩展 🔧 | 是否返回流对象(也可通过 `.stream()` 链式方法调用) |
47+
| `cache` | Number || `0` | monSQLize 扩展 🔧 | 缓存 TTL(毫秒),大于 0 时启用缓存 |
48+
| `meta` | Boolean/Object || `false` | monSQLize 扩展 🔧 | 返回查询元数据(执行时间、缓存命中率等) |
49+
50+
**图例说明**:
51+
-**MongoDB 原生**: 该参数是 MongoDB 官方支持的标准功能
52+
- 🔧 **monSQLize 扩展**: monSQLize 独有的扩展功能
53+
54+
**MongoDB 参考文档**:
55+
- [aggregate() 方法](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate/)
56+
- [聚合管道](https://www.mongodb.com/docs/manual/core/aggregation-pipeline/)
4757

4858
### allowDiskUse 说明
4959

docs/chaining-api.md

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,75 @@
44

55
monSQLize 现已支持完整的 MongoDB 风格链式调用 API,提供更直观、更灵活的查询构建方式。链式调用方法与 options 参数方式完全兼容,您可以根据需要选择任一方式。
66

7+
### 🔵 MongoDB 原生 vs monSQLize 扩展
8+
9+
本文档中的所有链式方法都是 **MongoDB 原生支持的游标方法**,monSQLize 提供了完整的封装和实现:
10+
11+
-**MongoDB 原生支持**: 所有列出的链式方法都对应 MongoDB 游标的原生方法
12+
- 🔄 **monSQLize 封装**: 在原生方法基础上增加了缓存、错误处理、性能监控等功能
13+
- 📚 **参考**: [MongoDB Cursor 官方文档](https://www.mongodb.com/docs/manual/reference/method/js-cursor/)
14+
15+
**monSQLize 独有的扩展参数** (仅在 options 方式中可用):
16+
- `cache` - 缓存 TTL 配置(monSQLize 扩展)
17+
- `stream` - 流式返回(通过 `.stream()` 方法调用)
18+
19+
---
20+
721
## 支持的链式方法
822

923
### find() 链式方法
1024

11-
| 方法 | 参数 | 说明 | 示例 |
12-
|------|------|------|------|
13-
| **`.limit(n)`** | `number` | 限制返回文档数量 | `.limit(10)` |
14-
| **`.skip(n)`** | `number` | 跳过文档数量 | `.skip(20)` |
15-
| **`.sort(spec)`** | `Object` | 排序规则 | `.sort({ price: -1 })` |
16-
| **`.project(spec)`** | `Object` | 字段投影 | `.project({ name: 1, price: 1 })` |
17-
| **`.hint(spec)`** | `Object\|String` | 索引提示 | `.hint({ category: 1 })` |
18-
| **`.collation(spec)`** | `Object` | 排序规则 | `.collation({ locale: 'zh' })` |
19-
| **`.comment(str)`** | `String` | 查询注释 | `.comment('test query')` |
20-
| **`.maxTimeMS(ms)`** | `Number` | 超时时间 | `.maxTimeMS(5000)` |
21-
| **`.batchSize(n)`** | `Number` | 批处理大小 | `.batchSize(100)` |
22-
| **`.explain(v)`** | `String` | 执行计划 | `.explain('executionStats')` |
23-
| **`.stream()`** | - | 返回流 | `.stream()` |
24-
| **`.toArray()`** | - | 显式执行 | `.toArray()` |
25-
26-
#### aggregate() 链式方法
27-
28-
| 方法 | 参数 | 说明 | 示例 |
29-
|------|------|------|------|
30-
| **`.hint(spec)`** | `Object\|String` | 索引提示 | `.hint({ status: 1 })` |
31-
| **`.collation(spec)`** | `Object` | 排序规则 | `.collation({ locale: 'zh' })` |
32-
| **`.comment(str)`** | `String` | 查询注释 | `.comment('test')` |
33-
| **`.maxTimeMS(ms)`** | `Number` | 超时时间 | `.maxTimeMS(5000)` |
34-
| **`.allowDiskUse(bool)`** | `Boolean` | 允许磁盘使用 | `.allowDiskUse(true)` |
35-
| **`.batchSize(n)`** | `Number` | 批处理大小 | `.batchSize(100)` |
36-
| **`.explain(v)`** | `String` | 执行计划 | `.explain('executionStats')` |
37-
| **`.stream()`** | - | 返回流 | `.stream()` |
38-
| **`.toArray()`** | - | 显式执行 | `.toArray()` |
25+
所有方法均为 **MongoDB 原生支持**
26+
27+
| 方法 | 参数 | MongoDB 原生 | 说明 | 示例 |
28+
|------|------|-------------|------|------|
29+
| **`.limit(n)`** | `number` || 限制返回文档数量 | `.limit(10)` |
30+
| **`.skip(n)`** | `number` || 跳过文档数量 | `.skip(20)` |
31+
| **`.sort(spec)`** | `Object` || 排序规则 | `.sort({ price: -1 })` |
32+
| **`.project(spec)`** | `Object` || 字段投影 | `.project({ name: 1, price: 1 })` |
33+
| **`.hint(spec)`** | `Object\|String` || 索引提示 | `.hint({ category: 1 })` |
34+
| **`.collation(spec)`** | `Object` || 排序规则 | `.collation({ locale: 'zh' })` |
35+
| **`.comment(str)`** | `String` || 查询注释 | `.comment('test query')` |
36+
| **`.maxTimeMS(ms)`** | `Number` || 超时时间 | `.maxTimeMS(5000)` |
37+
| **`.batchSize(n)`** | `Number` || 批处理大小 | `.batchSize(100)` |
38+
| **`.explain(v)`** | `String` || 执行计划 | `.explain('executionStats')` |
39+
| **`.stream()`** | - || 返回流 | `.stream()` |
40+
| **`.toArray()`** | - || 显式执行 | `.toArray()` |
41+
42+
**MongoDB 参考文档**:
43+
- [cursor.limit()](https://www.mongodb.com/docs/manual/reference/method/cursor.limit/)
44+
- [cursor.skip()](https://www.mongodb.com/docs/manual/reference/method/cursor.skip/)
45+
- [cursor.sort()](https://www.mongodb.com/docs/manual/reference/method/cursor.sort/)
46+
- [cursor.project()](https://www.mongodb.com/docs/manual/reference/method/cursor.project/)
47+
- [更多游标方法...](https://www.mongodb.com/docs/manual/reference/method/js-cursor/)
48+
49+
---
50+
51+
### aggregate() 链式方法
52+
53+
所有方法均为 **MongoDB 原生支持**
54+
55+
### aggregate() 链式方法
56+
57+
所有方法均为 **MongoDB 原生支持**
58+
59+
| 方法 | 参数 | MongoDB 原生 | 说明 | 示例 |
60+
|------|------|-------------|------|------|
61+
| **`.hint(spec)`** | `Object\|String` || 索引提示 | `.hint({ status: 1 })` |
62+
| **`.collation(spec)`** | `Object` || 排序规则 | `.collation({ locale: 'zh' })` |
63+
| **`.comment(str)`** | `String` || 查询注释 | `.comment('test')` |
64+
| **`.maxTimeMS(ms)`** | `Number` || 超时时间 | `.maxTimeMS(5000)` |
65+
| **`.allowDiskUse(bool)`** | `Boolean` || 允许磁盘使用 | `.allowDiskUse(true)` |
66+
| **`.batchSize(n)`** | `Number` || 批处理大小 | `.batchSize(100)` |
67+
| **`.explain(v)`** | `String` || 执行计划 | `.explain('executionStats')` |
68+
| **`.stream()`** | - || 返回流 | `.stream()` |
69+
| **`.toArray()`** | - || 显式执行 | `.toArray()` |
70+
71+
**MongoDB 参考文档**:
72+
- [cursor.hint()](https://www.mongodb.com/docs/manual/reference/method/cursor.hint/)
73+
- [cursor.collation()](https://www.mongodb.com/docs/manual/reference/method/cursor.collation/)
74+
- [cursor.allowDiskUse()](https://www.mongodb.com/docs/manual/reference/method/cursor.allowDiskUse/)
75+
- [更多聚合游标方法...](https://www.mongodb.com/docs/manual/reference/method/js-cursor/)
3976

4077
---
4178

docs/count.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,25 @@ async count(query = {}, options = {})
4343

4444
### options 参数对象
4545

46-
| 参数 | 类型 | 必填 | 默认值 | 说明 |
47-
|------|------|------|--------|------|
48-
| `hint` | Object/String || - | 指定查询使用的索引(仅 countDocuments) |
49-
| `collation` | Object || - | 指定排序规则(用于字符串比较,仅 countDocuments) |
50-
| `skip` | Number || - | 跳过的文档数量(仅 countDocuments) |
51-
| `limit` | Number || - | 限制统计的文档数量(仅 countDocuments) |
52-
| `maxTimeMS` | Number || 全局配置 | 查询超时时间(毫秒) |
53-
| `cache` | Number || `0` | 缓存 TTL(毫秒),大于 0 时启用缓存 |
54-
| `comment` | String || - | 查询注释,用于生产环境日志跟踪和性能分析 |
55-
| `explain` | Boolean/String || - | 返回查询执行计划,可选值:`true``'queryPlanner'``'executionStats'``'allPlansExecution'` |
46+
| 参数 | 类型 | 必填 | 默认值 | 来源 | 说明 |
47+
|------|------|------|--------|------|------|
48+
| `hint` | Object/String || - | MongoDB 原生 ✅ | 指定查询使用的索引(仅 countDocuments) |
49+
| `collation` | Object || - | MongoDB 原生 ✅ | 指定排序规则(用于字符串比较,仅 countDocuments) |
50+
| `skip` | Number || - | MongoDB 原生 ✅ | 跳过的文档数量(仅 countDocuments) |
51+
| `limit` | Number || - | MongoDB 原生 ✅ | 限制统计的文档数量(仅 countDocuments) |
52+
| `maxTimeMS` | Number || 全局配置 | MongoDB 原生 ✅ | 查询超时时间(毫秒) |
53+
| `comment` | String || - | MongoDB 原生 ✅ | 查询注释,用于生产环境日志跟踪和性能分析 |
54+
| `explain` | Boolean/String || - | MongoDB 原生 ✅ | 返回查询执行计划,可选值:`true``'queryPlanner'``'executionStats'``'allPlansExecution'` |
55+
| `cache` | Number || `0` | monSQLize 扩展 🔧 | 缓存 TTL(毫秒),大于 0 时启用缓存 |
56+
| `meta` | Boolean/Object || `false` | monSQLize 扩展 🔧 | 返回查询元数据(执行时间、缓存命中率等) |
57+
58+
**图例说明**:
59+
-**MongoDB 原生**: 该参数是 MongoDB 官方支持的标准功能
60+
- 🔧 **monSQLize 扩展**: monSQLize 独有的扩展功能
61+
62+
**MongoDB 参考文档**:
63+
- [countDocuments()](https://www.mongodb.com/docs/manual/reference/method/db.collection.countDocuments/)
64+
- [estimatedDocumentCount()](https://www.mongodb.com/docs/manual/reference/method/db.collection.estimatedDocumentCount/)
5665

5766
### 性能优化说明
5867

docs/distinct.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,25 @@ async distinct(field, filter = {}, options = {})
4747

4848
### options 参数对象
4949

50-
**核心选项**(MongoDB 原生支持):
50+
**核心选项**(MongoDB 原生 ✅):
5151

52-
| 参数 | 类型 | 必填 | 默认值 | 说明 |
53-
|------|------|------|--------|------|
54-
| `maxTimeMS` | Number || - | 查询超时时间(毫秒),防止长时间查询阻塞 |
55-
| `collation` | Object || - | 排序规则配置,用于字符串比较和去重(如不区分大小写) |
56-
| `comment` | String || - | 查询注释,用于日志和性能分析 |
57-
| `session` | ClientSession || - | 事务会话对象,用于事务操作 |
52+
| 参数 | 类型 | 必填 | 默认值 | 来源 | 说明 |
53+
|------|------|------|--------|------|------|
54+
| `maxTimeMS` | Number || - | MongoDB 原生 ✅ | 查询超时时间(毫秒),防止长时间查询阻塞 |
55+
| `collation` | Object || - | MongoDB 原生 ✅ | 排序规则配置,用于字符串比较和去重(如不区分大小写) |
56+
| `comment` | String || - | MongoDB 原生 ✅ | 查询注释,用于日志和性能分析 |
57+
| `session` | ClientSession || - | MongoDB 原生 ✅ | 事务会话对象,用于事务操作 |
5858

59-
**扩展选项**(monSQLize 增强):
59+
**扩展选项**(monSQLize 扩展 🔧):
6060

61-
| 参数 | 类型 | 必填 | 默认值 | 说明 |
62-
|------|------|------|--------|------|
63-
| `cache` | Number || `0` | 缓存 TTL(毫秒),大于 0 时启用缓存 |
64-
| `explain` | Boolean/String || - | 返回查询执行计划,可选值:`true``'queryPlanner'``'executionStats'``'allPlansExecution'` |
61+
| 参数 | 类型 | 必填 | 默认值 | 来源 | 说明 |
62+
|------|------|------|--------|------|------|
63+
| `cache` | Number || `0` | monSQLize 扩展 🔧 | 缓存 TTL(毫秒),大于 0 时启用缓存 |
64+
| `meta` | Boolean/Object || `false` | monSQLize 扩展 🔧 | 返回查询元数据(执行时间、缓存命中率等) |
65+
| `explain` | Boolean/String || - | MongoDB 原生 ✅ | 返回查询执行计划,可选值:`true``'queryPlanner'``'executionStats'``'allPlansExecution'` |
66+
67+
**MongoDB 参考文档**:
68+
- [distinct()](https://www.mongodb.com/docs/manual/reference/method/db.collection.distinct/)
6569

6670
### comment 配置
6771

docs/find.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,28 @@ MongoDB 标准查询条件对象,支持所有 MongoDB 查询操作符。
9090

9191
### options 对象属性
9292

93-
| 参数 | 类型 | 必填 | 默认值 | 说明 |
94-
|------|------|------|--------|------|
95-
| `projection` | Object/Array || - | 字段投影配置,指定返回的字段 |
96-
| `sort` | Object || - | 排序规则,如 `{ createdAt: -1, name: 1 }` |
97-
| `limit` | Number || 全局配置 | 限制返回的文档数量 |
98-
| `skip` | Number || - | 跳过指定数量的文档(不推荐大数据量使用) |
99-
| `hint` | Object/String || - | 指定查询使用的索引 |
100-
| `collation` | Object || - | 指定排序规则(用于字符串排序) |
101-
| `maxTimeMS` | Number || 全局配置 | 查询超时时间(毫秒) |
102-
| `stream` | Boolean || `false` | 是否返回流对象 |
103-
| `batchSize` | Number || - | 流式查询或数组查询时的批次大小 |
104-
| `cache` | Number || `0` | 缓存 TTL(毫秒),大于 0 时启用缓存 |
105-
| `comment` | String || - | 查询注释,用于生产环境日志跟踪和性能分析 |
106-
| `explain` | Boolean/String || - | 返回查询执行计划,可选值:`true``'queryPlanner'``'executionStats'``'allPlansExecution'` |
93+
| 参数 | 类型 | 必填 | 默认值 | 来源 | 说明 |
94+
|------|------|------|--------|------|------|
95+
| `projection` | Object/Array || - | MongoDB 原生 ✅ | 字段投影配置,指定返回的字段 |
96+
| `sort` | Object || - | MongoDB 原生 ✅ | 排序规则,如 `{ createdAt: -1, name: 1 }` |
97+
| `limit` | Number || 全局配置 | MongoDB 原生 ✅ | 限制返回的文档数量 |
98+
| `skip` | Number || - | MongoDB 原生 ✅ | 跳过指定数量的文档(不推荐大数据量使用) |
99+
| `hint` | Object/String || - | MongoDB 原生 ✅ | 指定查询使用的索引 |
100+
| `collation` | Object || - | MongoDB 原生 ✅ | 指定排序规则(用于字符串排序) |
101+
| `maxTimeMS` | Number || 全局配置 | MongoDB 原生 ✅ | 查询超时时间(毫秒) |
102+
| `batchSize` | Number || - | MongoDB 原生 ✅ | 流式查询或数组查询时的批次大小 |
103+
| `comment` | String || - | MongoDB 原生 ✅ | 查询注释,用于生产环境日志跟踪和性能分析 |
104+
| `explain` | Boolean/String || - | MongoDB 原生 ✅ | 返回查询执行计划,可选值:`true``'queryPlanner'``'executionStats'``'allPlansExecution'` |
105+
| `stream` | Boolean || `false` | monSQLize 扩展 🔧 | 是否返回流对象(也可通过 `.stream()` 链式方法调用) |
106+
| `cache` | Number || `0` | monSQLize 扩展 🔧 | 缓存 TTL(毫秒),大于 0 时启用缓存 |
107+
108+
**图例说明**:
109+
-**MongoDB 原生**: 该参数/方法是 MongoDB 官方支持的标准功能
110+
- 🔧 **monSQLize 扩展**: monSQLize 独有的扩展功能,提供额外的便利性
111+
112+
**MongoDB 参考文档**:
113+
- [find() 方法](https://www.mongodb.com/docs/manual/reference/method/db.collection.find/)
114+
- [游标方法](https://www.mongodb.com/docs/manual/reference/method/js-cursor/)
107115

108116
### comment 配置
109117

docs/findOne.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ MongoDB 查询条件对象,支持所有 MongoDB 查询操作符。
3030

3131
### options 对象属性
3232

33-
| 参数 | 类型 | 必填 | 默认值 | 说明 |
34-
|------|------|------|--------|------|
35-
| `projection` | Object/Array || - | 字段投影配置,指定返回的字段 |
36-
| `sort` | Object || - | 排序规则,如 `{ createdAt: -1, name: 1 }` |
37-
| `hint` | Object/String || - | 指定查询使用的索引 |
38-
| `collation` | Object || - | 指定排序规则(用于字符串排序) |
39-
| `maxTimeMS` | Number || 全局配置 | 查询超时时间(毫秒) |
40-
| `cache` | Number || `0` | 缓存 TTL(毫秒),大于 0 时启用缓存 |
41-
| `comment` | String || - | 查询注释,用于生产环境日志跟踪和性能分析 |
42-
| `explain` | Boolean/String || - | 返回查询执行计划,可选值:`true``'queryPlanner'``'executionStats'``'allPlansExecution'` |
33+
| 参数 | 类型 | 必填 | 默认值 | 来源 | 说明 |
34+
|------|------|------|--------|------|------|
35+
| `projection` | Object/Array || - | MongoDB 原生 ✅ | 字段投影配置,指定返回的字段 |
36+
| `sort` | Object || - | MongoDB 原生 ✅ | 排序规则,如 `{ createdAt: -1, name: 1 }` |
37+
| `hint` | Object/String || - | MongoDB 原生 ✅ | 指定查询使用的索引 |
38+
| `collation` | Object || - | MongoDB 原生 ✅ | 指定排序规则(用于字符串排序) |
39+
| `maxTimeMS` | Number || 全局配置 | MongoDB 原生 ✅ | 查询超时时间(毫秒) |
40+
| `comment` | String || - | MongoDB 原生 ✅ | 查询注释,用于生产环境日志跟踪和性能分析 |
41+
| `explain` | Boolean/String || - | MongoDB 原生 ✅ | 返回查询执行计划,可选值:`true``'queryPlanner'``'executionStats'``'allPlansExecution'` |
42+
| `cache` | Number || `0` | monSQLize 扩展 🔧 | 缓存 TTL(毫秒),大于 0 时启用缓存 |
43+
| `meta` | Boolean/Object || `false` | monSQLize 扩展 🔧 | 返回查询元数据(执行时间、缓存命中率等) |
44+
45+
**图例说明**:
46+
-**MongoDB 原生**: 该参数是 MongoDB 官方支持的标准功能
47+
- 🔧 **monSQLize 扩展**: monSQLize 独有的扩展功能
48+
49+
**MongoDB 参考文档**:
50+
- [findOne() 方法](https://www.mongodb.com/docs/manual/reference/method/db.collection.findOne/)
4351

4452
### comment 配置
4553

0 commit comments

Comments
 (0)