monsqlize 2.0.0 → 2.0.2
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 +461 -458
- package/README.md +7 -2
- package/changelogs/README.md +141 -138
- package/changelogs/v2.0.0.md +164 -164
- package/changelogs/v2.0.1.md +39 -0
- package/changelogs/v2.0.2.md +22 -0
- package/dist/cjs/index.cjs +329 -141
- package/dist/esm/index.mjs +329 -141
- package/dist/types/base.d.ts +81 -81
- package/dist/types/collection.d.ts +973 -973
- package/dist/types/expression.d.ts +115 -115
- package/dist/types/index.d.ts +23 -23
- package/dist/types/model.d.ts +489 -485
- package/dist/types/mongodb.d.ts +49 -49
- package/dist/types/monsqlize.d.ts +429 -429
- package/dist/types/pool.d.ts +84 -84
- package/dist/types/runtime.d.ts +315 -315
- package/dist/types/saga.d.ts +121 -121
- package/dist/types/slow-query-log.d.ts +126 -126
- package/dist/types/sync.d.ts +103 -103
- package/package.json +101 -99
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import type { ChangeStream, Document, FindOptions, Sort } from 'mongodb';
|
|
2
|
-
|
|
3
|
-
/** Meta options for controlling timing/cache info in query results. */
|
|
4
|
-
export interface MetaOptions {
|
|
5
|
-
/** 'op' = operation-level timing only; 'sub' = include sub-step timings (findPage only) */
|
|
6
|
-
level?: 'op' | 'sub';
|
|
7
|
-
/** Include cache hit/miss/ttl info in meta */
|
|
8
|
-
includeCache?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** Query options that request the v1 `{ data, meta }` wrapper. */
|
|
12
|
-
export interface QueryMetaOption extends Record<string, unknown> {
|
|
13
|
-
/** Include operation timing metadata in the resolved query result. */
|
|
14
|
-
meta: true | MetaOptions;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Cursor-based page navigation info returned by findPage. */
|
|
18
|
-
export interface PageInfo {
|
|
19
|
-
hasNext: boolean;
|
|
20
|
-
hasPrev: boolean;
|
|
21
|
-
startCursor: string | null;
|
|
22
|
-
endCursor: string | null;
|
|
23
|
-
/** Target logical page number (cursor/offset-jump modes only) */
|
|
24
|
-
currentPage?: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Totals/count info returned by findPage when totals mode is enabled. */
|
|
1
|
+
import type { ChangeStream, Document, FindOptions, Sort } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
/** Meta options for controlling timing/cache info in query results. */
|
|
4
|
+
export interface MetaOptions {
|
|
5
|
+
/** 'op' = operation-level timing only; 'sub' = include sub-step timings (findPage only) */
|
|
6
|
+
level?: 'op' | 'sub';
|
|
7
|
+
/** Include cache hit/miss/ttl info in meta */
|
|
8
|
+
includeCache?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Query options that request the v1 `{ data, meta }` wrapper. */
|
|
12
|
+
export interface QueryMetaOption extends Record<string, unknown> {
|
|
13
|
+
/** Include operation timing metadata in the resolved query result. */
|
|
14
|
+
meta: true | MetaOptions;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Cursor-based page navigation info returned by findPage. */
|
|
18
|
+
export interface PageInfo {
|
|
19
|
+
hasNext: boolean;
|
|
20
|
+
hasPrev: boolean;
|
|
21
|
+
startCursor: string | null;
|
|
22
|
+
endCursor: string | null;
|
|
23
|
+
/** Target logical page number (cursor/offset-jump modes only) */
|
|
24
|
+
currentPage?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Totals/count info returned by findPage when totals mode is enabled. */
|
|
28
28
|
export interface TotalsInfo {
|
|
29
29
|
mode: 'async' | 'sync' | 'approx';
|
|
30
|
-
/** async: null = not ready yet; approx: undefined = unknown/approximate */
|
|
31
|
-
total?: number | null;
|
|
32
|
-
totalPages?: number | null;
|
|
33
|
-
/** Short token for async totals polling */
|
|
34
|
-
token?: string;
|
|
35
|
-
/** Write timestamp (ms) if from cache */
|
|
36
|
-
ts?: number;
|
|
37
|
-
/** Error identifier for async mode failures */
|
|
30
|
+
/** async: null = not ready yet; approx: undefined = unknown/approximate */
|
|
31
|
+
total?: number | null;
|
|
32
|
+
totalPages?: number | null;
|
|
33
|
+
/** Short token for async totals polling */
|
|
34
|
+
token?: string;
|
|
35
|
+
/** Write timestamp (ms) if from cache */
|
|
36
|
+
ts?: number;
|
|
37
|
+
/** Error identifier for async mode failures */
|
|
38
38
|
error?: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -46,132 +46,132 @@ type SyncTotalsInfo = TotalsInfo & {
|
|
|
46
46
|
totalPages: number;
|
|
47
47
|
};
|
|
48
48
|
type LegacySyncTotalsInfo<TSchema = any> = unknown extends TSchema ? any : SyncTotalsInfo;
|
|
49
|
-
|
|
50
|
-
/** Timing/meta info returned by findPage when the meta option is enabled. */
|
|
51
|
-
export interface MetaInfo {
|
|
52
|
-
op: string;
|
|
53
|
-
ns: { iid: string; type: string; db: string; coll: string };
|
|
54
|
-
db?: string;
|
|
55
|
-
collection?: string;
|
|
56
|
-
timestamp?: number;
|
|
57
|
-
startTs: number;
|
|
58
|
-
endTs: number;
|
|
59
|
-
durationMs: number;
|
|
60
|
-
maxTimeMS?: number;
|
|
61
|
-
fromCache?: boolean;
|
|
62
|
-
cacheHit?: boolean;
|
|
63
|
-
cacheTtl?: number;
|
|
64
|
-
keyHash?: string;
|
|
65
|
-
page?: number;
|
|
66
|
-
after?: boolean;
|
|
67
|
-
before?: boolean;
|
|
68
|
-
hops?: number;
|
|
69
|
-
step?: number;
|
|
70
|
-
/** Sub-step timings (level='sub' only) */
|
|
71
|
-
steps?: Array<{ phase: 'hop' | 'offset' | 'fetch' | 'totals'; name: string; index?: number; durationMs: number }>;
|
|
72
|
-
error?: { code?: string; message: string };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Bookmark/cursor jump configuration for deep pagination. */
|
|
76
|
-
export interface JumpOptions {
|
|
77
|
-
/** Bookmark density: store bookmark every N pages (default 10) */
|
|
78
|
-
step?: number;
|
|
79
|
-
/** Max cursor-walking hops per jump (default 20) */
|
|
80
|
-
maxHops?: number;
|
|
81
|
-
/** Optional custom key dimensions for bookmark keying */
|
|
82
|
-
keyDims?: object;
|
|
83
|
-
/** Custom bookmark reader — returns cursor string or null */
|
|
84
|
-
getBookmark?: (params: { keyDims: unknown; page: number }) => Promise<string | null>;
|
|
85
|
-
/** Custom bookmark writer */
|
|
86
|
-
saveBookmark?: (params: { keyDims: unknown; page: number; cursor: string; ttlMs?: number }) => Promise<void>;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Offset-based fallback configuration for small-range pages in findPage. */
|
|
90
|
-
export interface OffsetJumpOptions {
|
|
91
|
-
/** Enable offset fallback when skip <= maxSkip (default false) */
|
|
92
|
-
enable?: boolean;
|
|
93
|
-
/** Max skip before falling back to cursor-jump (default 50000) */
|
|
94
|
-
maxSkip?: number;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Totals/count mode configuration for findPage. */
|
|
98
|
-
export interface TotalsOptions {
|
|
99
|
-
/** Counting strategy (default 'none') */
|
|
100
|
-
mode?: 'none' | 'async' | 'approx' | 'sync';
|
|
101
|
-
/** Timeout for countDocuments (sync/async modes, ms) */
|
|
102
|
-
maxTimeMS?: number;
|
|
103
|
-
/** Cache TTL for totals (async/approx modes, ms; default 10 min) */
|
|
104
|
-
ttlMs?: number;
|
|
105
|
-
/** Index hint for count query */
|
|
106
|
-
hint?: unknown;
|
|
107
|
-
/** Collation for count query */
|
|
108
|
-
collation?: unknown;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Stream query options for collection.stream(). */
|
|
112
|
-
export interface StreamOptions {
|
|
113
|
-
projection?: Record<string, unknown> | string[];
|
|
114
|
-
sort?: Record<string, 1 | -1>;
|
|
115
|
-
limit?: number;
|
|
116
|
-
skip?: number;
|
|
117
|
-
/** Cursor batch size (default 1000) */
|
|
118
|
-
batchSize?: number;
|
|
119
|
-
maxTimeMS?: number;
|
|
120
|
-
hint?: unknown;
|
|
121
|
-
collation?: unknown;
|
|
122
|
-
noCursorTimeout?: boolean;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Explain/query plan options for collection.explain(). */
|
|
126
|
-
export interface ExplainOptions {
|
|
127
|
-
projection?: Record<string, unknown>;
|
|
128
|
-
sort?: Record<string, 1 | -1>;
|
|
129
|
-
limit?: number;
|
|
130
|
-
skip?: number;
|
|
131
|
-
maxTimeMS?: number;
|
|
132
|
-
hint?: unknown;
|
|
133
|
-
collation?: unknown;
|
|
134
|
-
/** Verbosity level (default 'queryPlanner') */
|
|
135
|
-
verbosity?: 'queryPlanner' | 'executionStats' | 'allPlansExecution';
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** MongoDB query execution plan result returned by collection.explain(). */
|
|
139
|
-
export interface ExplainResult {
|
|
140
|
-
queryPlanner: {
|
|
141
|
-
plannerVersion: number;
|
|
142
|
-
namespace: string;
|
|
143
|
-
indexFilterSet: boolean;
|
|
144
|
-
parsedQuery?: unknown;
|
|
145
|
-
winningPlan: unknown;
|
|
146
|
-
rejectedPlans: unknown[];
|
|
147
|
-
};
|
|
148
|
-
executionStats?: {
|
|
149
|
-
executionSuccess: boolean;
|
|
150
|
-
nReturned: number;
|
|
151
|
-
executionTimeMillis: number;
|
|
152
|
-
totalKeysExamined: number;
|
|
153
|
-
totalDocsExamined: number;
|
|
154
|
-
executionStages: unknown;
|
|
155
|
-
allPlansExecution?: unknown[];
|
|
156
|
-
};
|
|
157
|
-
serverInfo?: {
|
|
158
|
-
host: string;
|
|
159
|
-
port: number;
|
|
160
|
-
version: string;
|
|
161
|
-
gitVersion: string;
|
|
162
|
-
};
|
|
163
|
-
ok: number;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export interface HealthView {
|
|
167
|
-
status: 'up' | 'down';
|
|
168
|
-
connected: boolean;
|
|
169
|
-
/** @since v1 — driver connection state alias */
|
|
170
|
-
driver?: { connected: boolean };
|
|
171
|
-
defaults?: Record<string, unknown>;
|
|
172
|
-
cache?: Record<string, unknown>;
|
|
173
|
-
}
|
|
174
|
-
|
|
49
|
+
|
|
50
|
+
/** Timing/meta info returned by findPage when the meta option is enabled. */
|
|
51
|
+
export interface MetaInfo {
|
|
52
|
+
op: string;
|
|
53
|
+
ns: { iid: string; type: string; db: string; coll: string };
|
|
54
|
+
db?: string;
|
|
55
|
+
collection?: string;
|
|
56
|
+
timestamp?: number;
|
|
57
|
+
startTs: number;
|
|
58
|
+
endTs: number;
|
|
59
|
+
durationMs: number;
|
|
60
|
+
maxTimeMS?: number;
|
|
61
|
+
fromCache?: boolean;
|
|
62
|
+
cacheHit?: boolean;
|
|
63
|
+
cacheTtl?: number;
|
|
64
|
+
keyHash?: string;
|
|
65
|
+
page?: number;
|
|
66
|
+
after?: boolean;
|
|
67
|
+
before?: boolean;
|
|
68
|
+
hops?: number;
|
|
69
|
+
step?: number;
|
|
70
|
+
/** Sub-step timings (level='sub' only) */
|
|
71
|
+
steps?: Array<{ phase: 'hop' | 'offset' | 'fetch' | 'totals'; name: string; index?: number; durationMs: number }>;
|
|
72
|
+
error?: { code?: string; message: string };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Bookmark/cursor jump configuration for deep pagination. */
|
|
76
|
+
export interface JumpOptions {
|
|
77
|
+
/** Bookmark density: store bookmark every N pages (default 10) */
|
|
78
|
+
step?: number;
|
|
79
|
+
/** Max cursor-walking hops per jump (default 20) */
|
|
80
|
+
maxHops?: number;
|
|
81
|
+
/** Optional custom key dimensions for bookmark keying */
|
|
82
|
+
keyDims?: object;
|
|
83
|
+
/** Custom bookmark reader — returns cursor string or null */
|
|
84
|
+
getBookmark?: (params: { keyDims: unknown; page: number }) => Promise<string | null>;
|
|
85
|
+
/** Custom bookmark writer */
|
|
86
|
+
saveBookmark?: (params: { keyDims: unknown; page: number; cursor: string; ttlMs?: number }) => Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Offset-based fallback configuration for small-range pages in findPage. */
|
|
90
|
+
export interface OffsetJumpOptions {
|
|
91
|
+
/** Enable offset fallback when skip <= maxSkip (default false) */
|
|
92
|
+
enable?: boolean;
|
|
93
|
+
/** Max skip before falling back to cursor-jump (default 50000) */
|
|
94
|
+
maxSkip?: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Totals/count mode configuration for findPage. */
|
|
98
|
+
export interface TotalsOptions {
|
|
99
|
+
/** Counting strategy (default 'none') */
|
|
100
|
+
mode?: 'none' | 'async' | 'approx' | 'sync';
|
|
101
|
+
/** Timeout for countDocuments (sync/async modes, ms) */
|
|
102
|
+
maxTimeMS?: number;
|
|
103
|
+
/** Cache TTL for totals (async/approx modes, ms; default 10 min) */
|
|
104
|
+
ttlMs?: number;
|
|
105
|
+
/** Index hint for count query */
|
|
106
|
+
hint?: unknown;
|
|
107
|
+
/** Collation for count query */
|
|
108
|
+
collation?: unknown;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Stream query options for collection.stream(). */
|
|
112
|
+
export interface StreamOptions {
|
|
113
|
+
projection?: Record<string, unknown> | string[];
|
|
114
|
+
sort?: Record<string, 1 | -1>;
|
|
115
|
+
limit?: number;
|
|
116
|
+
skip?: number;
|
|
117
|
+
/** Cursor batch size (default 1000) */
|
|
118
|
+
batchSize?: number;
|
|
119
|
+
maxTimeMS?: number;
|
|
120
|
+
hint?: unknown;
|
|
121
|
+
collation?: unknown;
|
|
122
|
+
noCursorTimeout?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Explain/query plan options for collection.explain(). */
|
|
126
|
+
export interface ExplainOptions {
|
|
127
|
+
projection?: Record<string, unknown>;
|
|
128
|
+
sort?: Record<string, 1 | -1>;
|
|
129
|
+
limit?: number;
|
|
130
|
+
skip?: number;
|
|
131
|
+
maxTimeMS?: number;
|
|
132
|
+
hint?: unknown;
|
|
133
|
+
collation?: unknown;
|
|
134
|
+
/** Verbosity level (default 'queryPlanner') */
|
|
135
|
+
verbosity?: 'queryPlanner' | 'executionStats' | 'allPlansExecution';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** MongoDB query execution plan result returned by collection.explain(). */
|
|
139
|
+
export interface ExplainResult {
|
|
140
|
+
queryPlanner: {
|
|
141
|
+
plannerVersion: number;
|
|
142
|
+
namespace: string;
|
|
143
|
+
indexFilterSet: boolean;
|
|
144
|
+
parsedQuery?: unknown;
|
|
145
|
+
winningPlan: unknown;
|
|
146
|
+
rejectedPlans: unknown[];
|
|
147
|
+
};
|
|
148
|
+
executionStats?: {
|
|
149
|
+
executionSuccess: boolean;
|
|
150
|
+
nReturned: number;
|
|
151
|
+
executionTimeMillis: number;
|
|
152
|
+
totalKeysExamined: number;
|
|
153
|
+
totalDocsExamined: number;
|
|
154
|
+
executionStages: unknown;
|
|
155
|
+
allPlansExecution?: unknown[];
|
|
156
|
+
};
|
|
157
|
+
serverInfo?: {
|
|
158
|
+
host: string;
|
|
159
|
+
port: number;
|
|
160
|
+
version: string;
|
|
161
|
+
gitVersion: string;
|
|
162
|
+
};
|
|
163
|
+
ok: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface HealthView {
|
|
167
|
+
status: 'up' | 'down';
|
|
168
|
+
connected: boolean;
|
|
169
|
+
/** @since v1 — driver connection state alias */
|
|
170
|
+
driver?: { connected: boolean };
|
|
171
|
+
defaults?: Record<string, unknown>;
|
|
172
|
+
cache?: Record<string, unknown>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
175
|
export interface InsertOneResult {
|
|
176
176
|
acknowledged: boolean;
|
|
177
177
|
insertedId: any;
|
|
@@ -182,7 +182,7 @@ export interface InsertManyResult {
|
|
|
182
182
|
insertedCount: number;
|
|
183
183
|
insertedIds: Record<number, any>;
|
|
184
184
|
}
|
|
185
|
-
|
|
185
|
+
|
|
186
186
|
export interface UpdateResult {
|
|
187
187
|
acknowledged: boolean;
|
|
188
188
|
matchedCount: number;
|
|
@@ -190,42 +190,42 @@ export interface UpdateResult {
|
|
|
190
190
|
upsertedCount: number;
|
|
191
191
|
upsertedId: any;
|
|
192
192
|
}
|
|
193
|
-
|
|
194
|
-
export interface DeleteResult {
|
|
195
|
-
acknowledged: boolean;
|
|
196
|
-
deletedCount: number;
|
|
197
|
-
}
|
|
198
|
-
|
|
193
|
+
|
|
194
|
+
export interface DeleteResult {
|
|
195
|
+
acknowledged: boolean;
|
|
196
|
+
deletedCount: number;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
199
|
export interface FindPageOptions<TSchema = any> {
|
|
200
|
-
query?: Document;
|
|
201
|
-
page?: number;
|
|
202
|
-
limit?: number;
|
|
203
|
-
after?: string;
|
|
204
|
-
before?: string;
|
|
205
|
-
sort?: Sort;
|
|
206
|
-
projection?: Document;
|
|
207
|
-
pipeline?: Document[];
|
|
208
|
-
/** Totals/count configuration */
|
|
209
|
-
totals?: TotalsOptions;
|
|
210
|
-
stream?: boolean;
|
|
211
|
-
explain?: boolean | string;
|
|
212
|
-
/** Query comment for server-side profiling. v1 compat — top-level shortcut for `options.comment`. */
|
|
213
|
-
comment?: string;
|
|
214
|
-
options?: FindOptions;
|
|
215
|
-
/** Cursor-walking bookmark jump configuration */
|
|
216
|
-
jump?: JumpOptions;
|
|
217
|
-
/** Offset-based fallback for small page ranges */
|
|
218
|
-
offsetJump?: OffsetJumpOptions;
|
|
219
|
-
maxTimeMS?: number;
|
|
220
|
-
hint?: Document | string;
|
|
221
|
-
collation?: Document;
|
|
222
|
-
batchSize?: number;
|
|
223
|
-
/** Cache TTL in milliseconds */
|
|
224
|
-
cache?: number;
|
|
225
|
-
/** Include timing/meta info in result — pass true or MetaOptions for sub-step detail */
|
|
226
|
-
meta?: boolean | MetaOptions;
|
|
227
|
-
}
|
|
228
|
-
|
|
200
|
+
query?: Document;
|
|
201
|
+
page?: number;
|
|
202
|
+
limit?: number;
|
|
203
|
+
after?: string;
|
|
204
|
+
before?: string;
|
|
205
|
+
sort?: Sort;
|
|
206
|
+
projection?: Document;
|
|
207
|
+
pipeline?: Document[];
|
|
208
|
+
/** Totals/count configuration */
|
|
209
|
+
totals?: TotalsOptions;
|
|
210
|
+
stream?: boolean;
|
|
211
|
+
explain?: boolean | string;
|
|
212
|
+
/** Query comment for server-side profiling. v1 compat — top-level shortcut for `options.comment`. */
|
|
213
|
+
comment?: string;
|
|
214
|
+
options?: FindOptions;
|
|
215
|
+
/** Cursor-walking bookmark jump configuration */
|
|
216
|
+
jump?: JumpOptions;
|
|
217
|
+
/** Offset-based fallback for small page ranges */
|
|
218
|
+
offsetJump?: OffsetJumpOptions;
|
|
219
|
+
maxTimeMS?: number;
|
|
220
|
+
hint?: Document | string;
|
|
221
|
+
collation?: Document;
|
|
222
|
+
batchSize?: number;
|
|
223
|
+
/** Cache TTL in milliseconds */
|
|
224
|
+
cache?: number;
|
|
225
|
+
/** Include timing/meta info in result — pass true or MetaOptions for sub-step detail */
|
|
226
|
+
meta?: boolean | MetaOptions;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
229
|
export interface FindPageResult<TSchema = any> {
|
|
230
230
|
items: TSchema[];
|
|
231
231
|
pageInfo: LegacyPageInfo<TSchema>;
|
|
@@ -236,796 +236,796 @@ export interface FindPageResult<TSchema = any> {
|
|
|
236
236
|
|
|
237
237
|
export interface FindAndCountResult<TSchema = any> {
|
|
238
238
|
data: TSchema[];
|
|
239
|
-
total: number;
|
|
240
|
-
/** @deprecated Use `data`. v1 backward-compat alias — will be removed in a future major. */
|
|
241
|
-
documents?: TSchema[];
|
|
242
|
-
}
|
|
243
|
-
|
|
239
|
+
total: number;
|
|
240
|
+
/** @deprecated Use `data`. v1 backward-compat alias — will be removed in a future major. */
|
|
241
|
+
documents?: TSchema[];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
244
|
export interface FindChain<TSchema = any, TPromise = TSchema[]> extends Promise<TPromise> {
|
|
245
|
-
limit(value: number): FindChain<TSchema, TPromise>;
|
|
246
|
-
skip(value: number): FindChain<TSchema, TPromise>;
|
|
247
|
-
sort(value: Sort | Record<string, 1 | -1>): FindChain<TSchema, TPromise>;
|
|
248
|
-
project(value: Document): FindChain<TSchema, TPromise>;
|
|
249
|
-
hint(value: unknown): FindChain<TSchema, TPromise>;
|
|
250
|
-
collation(value: Record<string, unknown>): FindChain<TSchema, TPromise>;
|
|
251
|
-
comment(value: string): FindChain<TSchema, TPromise>;
|
|
252
|
-
maxTimeMS(value: number): FindChain<TSchema, TPromise>;
|
|
253
|
-
batchSize(value: number): FindChain<TSchema, TPromise>;
|
|
254
|
-
explain(verbosity?: boolean | string): Promise<unknown>;
|
|
255
|
-
stream(): NodeJS.ReadableStream;
|
|
256
|
-
toArray(): Promise<TSchema[]>;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export interface AggregateChain<TResult = unknown, TPromise = TResult[]> extends Promise<TPromise> {
|
|
260
|
-
hint(value: unknown): AggregateChain<TResult, TPromise>;
|
|
261
|
-
collation(value: Record<string, unknown>): AggregateChain<TResult, TPromise>;
|
|
262
|
-
comment(value: string): AggregateChain<TResult, TPromise>;
|
|
263
|
-
maxTimeMS(value: number): AggregateChain<TResult, TPromise>;
|
|
264
|
-
allowDiskUse(value: boolean): AggregateChain<TResult, TPromise>;
|
|
265
|
-
batchSize(value: number): AggregateChain<TResult, TPromise>;
|
|
266
|
-
explain(verbosity?: boolean | string): Promise<unknown>;
|
|
267
|
-
stream(): NodeJS.ReadableStream;
|
|
268
|
-
toArray(): Promise<TResult[]>;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/** Write concern options for batch operations. */
|
|
272
|
-
export interface WriteConcern {
|
|
273
|
-
/** Write acknowledgement level (default: 1). */
|
|
274
|
-
w?: number | 'majority';
|
|
275
|
-
/** Wait for journal flush before acknowledging (default: false). */
|
|
276
|
-
j?: boolean;
|
|
277
|
-
/** Write timeout in milliseconds. */
|
|
278
|
-
wtimeout?: number;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/** Per-batch retry record appended to batch result `retries` arrays. */
|
|
282
|
-
export interface BatchRetryRecord {
|
|
283
|
-
batchIndex: number;
|
|
284
|
-
attempt: number;
|
|
285
|
-
/** @alias attempt — v1 compat: v1 runtime emitted `attempts` (plural). */
|
|
286
|
-
attempts?: number;
|
|
287
|
-
maxAttempts: number;
|
|
288
|
-
delay: number;
|
|
289
|
-
/** @since v1 — always `false` on retry records (the attempt that triggered the retry failed). */
|
|
290
|
-
success?: boolean;
|
|
291
|
-
error?: Error;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/** Progress callback payload delivered for each completed batch. */
|
|
295
|
-
export interface BatchProgress {
|
|
296
|
-
currentBatch: number;
|
|
297
|
-
totalBatches: number;
|
|
298
|
-
inserted?: number;
|
|
299
|
-
modified?: number;
|
|
300
|
-
deleted?: number;
|
|
301
|
-
/** Total document count (null when not yet known). */
|
|
302
|
-
total: number | null;
|
|
303
|
-
/** Completion percentage (null when total is unknown). */
|
|
304
|
-
percentage: number | null;
|
|
305
|
-
errors: number;
|
|
306
|
-
retries: number;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** Payload supplied to the `onRetry` callback for each retry attempt. */
|
|
310
|
-
export interface RetryInfo {
|
|
311
|
-
batchIndex: number;
|
|
312
|
-
attempt: number;
|
|
313
|
-
maxAttempts: number;
|
|
314
|
-
error: Error;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/** Options for insertBatch operations. */
|
|
318
|
-
export interface InsertBatchOptions {
|
|
319
|
-
/** Number of documents per batch (default: 1000). */
|
|
320
|
-
batchSize?: number;
|
|
321
|
-
/** Maximum number of concurrent batch writes. */
|
|
322
|
-
concurrency?: number;
|
|
323
|
-
/** Ordered inserts — stop on first error when true. */
|
|
324
|
-
ordered?: boolean;
|
|
325
|
-
/** Progress callback invoked after each batch. */
|
|
326
|
-
onProgress?: (progress: BatchProgress) => void;
|
|
327
|
-
/** Error handling strategy. */
|
|
328
|
-
onError?: 'stop' | 'skip' | 'collect' | 'retry';
|
|
329
|
-
/** Number of retry attempts per batch on transient failure. */
|
|
330
|
-
retryAttempts?: number;
|
|
331
|
-
/** Delay between retries in milliseconds. */
|
|
332
|
-
retryDelay?: number;
|
|
333
|
-
/** Retry callback invoked before each retry attempt. */
|
|
334
|
-
onRetry?: (retryInfo: RetryInfo) => void;
|
|
335
|
-
/** MongoDB write concern. */
|
|
336
|
-
writeConcern?: WriteConcern;
|
|
337
|
-
/** Skip MongoDB document validation. */
|
|
338
|
-
bypassDocumentValidation?: boolean;
|
|
339
|
-
/** Query comment for server-side profiling. */
|
|
340
|
-
comment?: string;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/** Options for deleteBatch operations. */
|
|
344
|
-
export interface DeleteBatchOptions {
|
|
345
|
-
/** Number of documents per batch (default: 1000). */
|
|
346
|
-
batchSize?: number;
|
|
347
|
-
/** Estimate total for progress reporting. */
|
|
348
|
-
estimateProgress?: boolean;
|
|
349
|
-
/** Progress callback invoked after each batch. */
|
|
350
|
-
onProgress?: (progress: BatchProgress) => void;
|
|
351
|
-
/** Error handling strategy. */
|
|
352
|
-
onError?: 'stop' | 'skip' | 'collect' | 'retry';
|
|
353
|
-
/** Number of retry attempts per batch on transient failure. */
|
|
354
|
-
retryAttempts?: number;
|
|
355
|
-
/** Delay between retries in milliseconds. */
|
|
356
|
-
retryDelay?: number;
|
|
357
|
-
/** Retry callback invoked before each retry attempt. */
|
|
358
|
-
onRetry?: (retryInfo: RetryInfo) => void;
|
|
359
|
-
/** MongoDB write concern. */
|
|
360
|
-
writeConcern?: WriteConcern;
|
|
361
|
-
/** Query comment for server-side profiling. */
|
|
362
|
-
comment?: string;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
export interface BatchErrorRecord {
|
|
366
|
-
batchIndex: number;
|
|
367
|
-
message: string;
|
|
368
|
-
/** Additional error details. */
|
|
369
|
-
details?: unknown;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
export interface InsertBatchResult {
|
|
373
|
-
acknowledged: boolean;
|
|
374
|
-
/** Total document count processed (never null for insert). */
|
|
375
|
-
totalCount: number;
|
|
376
|
-
insertedCount: number;
|
|
377
|
-
batchCount: number;
|
|
378
|
-
errors: BatchErrorRecord[];
|
|
379
|
-
insertedIds: Record<number, unknown>;
|
|
380
|
-
/** Per-batch retry records. */
|
|
381
|
-
retries: BatchRetryRecord[];
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
export interface UpdateBatchResult {
|
|
385
|
-
acknowledged: boolean;
|
|
386
|
-
totalCount: number | null;
|
|
387
|
-
matchedCount: number;
|
|
388
|
-
modifiedCount: number;
|
|
389
|
-
/** Number of documents upserted across all batches. */
|
|
390
|
-
upsertedCount: number;
|
|
391
|
-
batchCount: number;
|
|
392
|
-
errors: BatchErrorRecord[];
|
|
393
|
-
/** Per-batch retry records. */
|
|
394
|
-
retries: BatchRetryRecord[];
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
export interface DeleteBatchResult {
|
|
398
|
-
acknowledged: boolean;
|
|
399
|
-
totalCount: number | null;
|
|
400
|
-
deletedCount: number;
|
|
401
|
-
batchCount: number;
|
|
402
|
-
errors: BatchErrorRecord[];
|
|
403
|
-
/** Per-batch retry records. */
|
|
404
|
-
retries: BatchRetryRecord[];
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
export interface BatchWriteOptions {
|
|
408
|
-
batchSize?: number;
|
|
409
|
-
ordered?: boolean;
|
|
410
|
-
concurrency?: number;
|
|
411
|
-
onProgress?: (progress: BatchProgress) => void;
|
|
412
|
-
onError?: 'stop' | 'skip' | 'collect' | 'retry';
|
|
413
|
-
retryAttempts?: number;
|
|
414
|
-
retryDelay?: number;
|
|
415
|
-
onRetry?: (retryInfo: RetryInfo) => void;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/** Options for updateBatch operations. */
|
|
419
|
-
export interface UpdateBatchOptions {
|
|
420
|
-
/** Number of documents per batch (default: 1000). */
|
|
421
|
-
batchSize?: number;
|
|
422
|
-
/** Estimate total for progress reporting. */
|
|
423
|
-
estimateProgress?: boolean;
|
|
424
|
-
/** Progress callback invoked after each batch. */
|
|
425
|
-
onProgress?: (progress: BatchProgress) => void;
|
|
426
|
-
/** Error handling strategy. */
|
|
427
|
-
onError?: 'stop' | 'skip' | 'collect' | 'retry';
|
|
428
|
-
/** Number of retry attempts per batch on transient failure. */
|
|
429
|
-
retryAttempts?: number;
|
|
430
|
-
/** Delay between retries in milliseconds. */
|
|
431
|
-
retryDelay?: number;
|
|
432
|
-
/** Retry callback invoked before each retry attempt. */
|
|
433
|
-
onRetry?: (retryInfo: RetryInfo) => void;
|
|
434
|
-
/** MongoDB write concern. */
|
|
435
|
-
writeConcern?: WriteConcern;
|
|
436
|
-
/** Upsert documents that do not match the filter. */
|
|
437
|
-
upsert?: boolean;
|
|
438
|
-
/** Array filters for nested array updates. */
|
|
439
|
-
arrayFilters?: unknown[];
|
|
440
|
-
/** Query comment for server-side profiling. */
|
|
441
|
-
comment?: string;
|
|
442
|
-
/** Sort order used to paginate through batch cursor. */
|
|
443
|
-
sort?: Record<string, 1 | -1>;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
export interface IncrementOneOptions extends Record<string, unknown> {
|
|
447
|
-
returnDocument?: 'before' | 'after';
|
|
448
|
-
projection?: Record<string, unknown>;
|
|
449
|
-
$set?: Record<string, unknown>;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Result returned by {@link Collection.incrementOne}.
|
|
454
|
-
* The updated document is available via `.value` (or `null` if not found).
|
|
455
|
-
*/
|
|
456
|
-
export interface IncrementOneResult<TSchema = unknown> {
|
|
457
|
-
acknowledged: boolean;
|
|
458
|
-
matchedCount: number;
|
|
459
|
-
modifiedCount: number;
|
|
460
|
-
/** The document after the increment (or null when no match). */
|
|
461
|
-
value: TSchema | null;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
export interface IndexCreateResult {
|
|
465
|
-
name: string;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
export interface BookmarkPrewarmResult {
|
|
469
|
-
warmed: number;
|
|
470
|
-
failed: number;
|
|
471
|
-
keys: string[];
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
export interface BookmarkListResult {
|
|
475
|
-
count: number;
|
|
476
|
-
pages: number[];
|
|
477
|
-
keys: string[];
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
export interface BookmarkClearResult {
|
|
481
|
-
cleared: number;
|
|
482
|
-
pattern: string;
|
|
483
|
-
keysBefore: number;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
export interface BookmarkKeyDims<TSchema = unknown> extends Omit<FindPageOptions<TSchema>, 'page'> { }
|
|
487
|
-
|
|
488
|
-
export interface BookmarkCacheLike {
|
|
489
|
-
set(key: string, value: unknown): void | boolean | Promise<void> | Promise<boolean>;
|
|
490
|
-
get(key: string): unknown | Promise<unknown>;
|
|
491
|
-
delete?(key: string): boolean | Promise<boolean>;
|
|
492
|
-
keys?(pattern: string): string[] | Promise<string[]>;
|
|
493
|
-
delPattern?(pattern: string): number | Promise<number>;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
export interface AdminBuildInfoView {
|
|
497
|
-
version?: string;
|
|
498
|
-
versionArray?: number[];
|
|
499
|
-
gitVersion?: string;
|
|
500
|
-
bits?: number;
|
|
501
|
-
debug?: boolean;
|
|
502
|
-
maxBsonObjectSize?: number;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
export interface ServerStatusView {
|
|
506
|
-
connections: {
|
|
507
|
-
current?: number;
|
|
508
|
-
available?: number;
|
|
509
|
-
totalCreated?: number;
|
|
510
|
-
};
|
|
511
|
-
mem: {
|
|
512
|
-
resident?: number;
|
|
513
|
-
virtual?: number;
|
|
514
|
-
mapped?: number;
|
|
515
|
-
};
|
|
516
|
-
opcounters: {
|
|
517
|
-
insert?: number;
|
|
518
|
-
query?: number;
|
|
519
|
-
update?: number;
|
|
520
|
-
delete?: number;
|
|
521
|
-
getmore?: number;
|
|
522
|
-
command?: number;
|
|
523
|
-
};
|
|
524
|
-
network: {
|
|
525
|
-
bytesIn?: number;
|
|
526
|
-
bytesOut?: number;
|
|
527
|
-
numRequests?: number;
|
|
528
|
-
};
|
|
529
|
-
uptime?: number;
|
|
530
|
-
localTime?: Date;
|
|
531
|
-
version?: string;
|
|
532
|
-
process?: string;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
export interface DbStatsView {
|
|
536
|
-
db?: string;
|
|
537
|
-
collections?: number;
|
|
538
|
-
views?: number;
|
|
539
|
-
objects?: number;
|
|
540
|
-
avgObjSize?: number;
|
|
541
|
-
dataSize?: number;
|
|
542
|
-
storageSize?: number;
|
|
543
|
-
indexes?: number;
|
|
544
|
-
indexSize?: number;
|
|
545
|
-
totalSize?: number;
|
|
546
|
-
scaleFactor?: number;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
export interface AdminAccessor {
|
|
550
|
-
/** Pings the MongoDB server and returns true when reachable. */
|
|
551
|
-
ping(): Promise<boolean>;
|
|
552
|
-
/** Returns MongoDB server build information. */
|
|
553
|
-
buildInfo(): Promise<AdminBuildInfoView>;
|
|
554
|
-
/**
|
|
555
|
-
* Returns current server status metrics.
|
|
556
|
-
* @param options - Optional scale factor for byte values.
|
|
557
|
-
* @returns Server status snapshot.
|
|
558
|
-
*/
|
|
559
|
-
serverStatus(options?: { scale?: number; }): Promise<ServerStatusView>;
|
|
560
|
-
/**
|
|
561
|
-
* Returns database storage statistics.
|
|
562
|
-
* @param options - Optional scale factor for byte values.
|
|
563
|
-
* @returns Database stats view.
|
|
564
|
-
*/
|
|
565
|
-
stats(options?: { scale?: number; }): Promise<DbStatsView>;
|
|
566
|
-
}
|
|
567
|
-
|
|
245
|
+
limit(value: number): FindChain<TSchema, TPromise>;
|
|
246
|
+
skip(value: number): FindChain<TSchema, TPromise>;
|
|
247
|
+
sort(value: Sort | Record<string, 1 | -1>): FindChain<TSchema, TPromise>;
|
|
248
|
+
project(value: Document): FindChain<TSchema, TPromise>;
|
|
249
|
+
hint(value: unknown): FindChain<TSchema, TPromise>;
|
|
250
|
+
collation(value: Record<string, unknown>): FindChain<TSchema, TPromise>;
|
|
251
|
+
comment(value: string): FindChain<TSchema, TPromise>;
|
|
252
|
+
maxTimeMS(value: number): FindChain<TSchema, TPromise>;
|
|
253
|
+
batchSize(value: number): FindChain<TSchema, TPromise>;
|
|
254
|
+
explain(verbosity?: boolean | string): Promise<unknown>;
|
|
255
|
+
stream(): NodeJS.ReadableStream;
|
|
256
|
+
toArray(): Promise<TSchema[]>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface AggregateChain<TResult = unknown, TPromise = TResult[]> extends Promise<TPromise> {
|
|
260
|
+
hint(value: unknown): AggregateChain<TResult, TPromise>;
|
|
261
|
+
collation(value: Record<string, unknown>): AggregateChain<TResult, TPromise>;
|
|
262
|
+
comment(value: string): AggregateChain<TResult, TPromise>;
|
|
263
|
+
maxTimeMS(value: number): AggregateChain<TResult, TPromise>;
|
|
264
|
+
allowDiskUse(value: boolean): AggregateChain<TResult, TPromise>;
|
|
265
|
+
batchSize(value: number): AggregateChain<TResult, TPromise>;
|
|
266
|
+
explain(verbosity?: boolean | string): Promise<unknown>;
|
|
267
|
+
stream(): NodeJS.ReadableStream;
|
|
268
|
+
toArray(): Promise<TResult[]>;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Write concern options for batch operations. */
|
|
272
|
+
export interface WriteConcern {
|
|
273
|
+
/** Write acknowledgement level (default: 1). */
|
|
274
|
+
w?: number | 'majority';
|
|
275
|
+
/** Wait for journal flush before acknowledging (default: false). */
|
|
276
|
+
j?: boolean;
|
|
277
|
+
/** Write timeout in milliseconds. */
|
|
278
|
+
wtimeout?: number;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** Per-batch retry record appended to batch result `retries` arrays. */
|
|
282
|
+
export interface BatchRetryRecord {
|
|
283
|
+
batchIndex: number;
|
|
284
|
+
attempt: number;
|
|
285
|
+
/** @alias attempt — v1 compat: v1 runtime emitted `attempts` (plural). */
|
|
286
|
+
attempts?: number;
|
|
287
|
+
maxAttempts: number;
|
|
288
|
+
delay: number;
|
|
289
|
+
/** @since v1 — always `false` on retry records (the attempt that triggered the retry failed). */
|
|
290
|
+
success?: boolean;
|
|
291
|
+
error?: Error;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Progress callback payload delivered for each completed batch. */
|
|
295
|
+
export interface BatchProgress {
|
|
296
|
+
currentBatch: number;
|
|
297
|
+
totalBatches: number;
|
|
298
|
+
inserted?: number;
|
|
299
|
+
modified?: number;
|
|
300
|
+
deleted?: number;
|
|
301
|
+
/** Total document count (null when not yet known). */
|
|
302
|
+
total: number | null;
|
|
303
|
+
/** Completion percentage (null when total is unknown). */
|
|
304
|
+
percentage: number | null;
|
|
305
|
+
errors: number;
|
|
306
|
+
retries: number;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Payload supplied to the `onRetry` callback for each retry attempt. */
|
|
310
|
+
export interface RetryInfo {
|
|
311
|
+
batchIndex: number;
|
|
312
|
+
attempt: number;
|
|
313
|
+
maxAttempts: number;
|
|
314
|
+
error: Error;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Options for insertBatch operations. */
|
|
318
|
+
export interface InsertBatchOptions {
|
|
319
|
+
/** Number of documents per batch (default: 1000). */
|
|
320
|
+
batchSize?: number;
|
|
321
|
+
/** Maximum number of concurrent batch writes. */
|
|
322
|
+
concurrency?: number;
|
|
323
|
+
/** Ordered inserts — stop on first error when true. */
|
|
324
|
+
ordered?: boolean;
|
|
325
|
+
/** Progress callback invoked after each batch. */
|
|
326
|
+
onProgress?: (progress: BatchProgress) => void;
|
|
327
|
+
/** Error handling strategy. */
|
|
328
|
+
onError?: 'stop' | 'skip' | 'collect' | 'retry';
|
|
329
|
+
/** Number of retry attempts per batch on transient failure. */
|
|
330
|
+
retryAttempts?: number;
|
|
331
|
+
/** Delay between retries in milliseconds. */
|
|
332
|
+
retryDelay?: number;
|
|
333
|
+
/** Retry callback invoked before each retry attempt. */
|
|
334
|
+
onRetry?: (retryInfo: RetryInfo) => void;
|
|
335
|
+
/** MongoDB write concern. */
|
|
336
|
+
writeConcern?: WriteConcern;
|
|
337
|
+
/** Skip MongoDB document validation. */
|
|
338
|
+
bypassDocumentValidation?: boolean;
|
|
339
|
+
/** Query comment for server-side profiling. */
|
|
340
|
+
comment?: string;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Options for deleteBatch operations. */
|
|
344
|
+
export interface DeleteBatchOptions {
|
|
345
|
+
/** Number of documents per batch (default: 1000). */
|
|
346
|
+
batchSize?: number;
|
|
347
|
+
/** Estimate total for progress reporting. */
|
|
348
|
+
estimateProgress?: boolean;
|
|
349
|
+
/** Progress callback invoked after each batch. */
|
|
350
|
+
onProgress?: (progress: BatchProgress) => void;
|
|
351
|
+
/** Error handling strategy. */
|
|
352
|
+
onError?: 'stop' | 'skip' | 'collect' | 'retry';
|
|
353
|
+
/** Number of retry attempts per batch on transient failure. */
|
|
354
|
+
retryAttempts?: number;
|
|
355
|
+
/** Delay between retries in milliseconds. */
|
|
356
|
+
retryDelay?: number;
|
|
357
|
+
/** Retry callback invoked before each retry attempt. */
|
|
358
|
+
onRetry?: (retryInfo: RetryInfo) => void;
|
|
359
|
+
/** MongoDB write concern. */
|
|
360
|
+
writeConcern?: WriteConcern;
|
|
361
|
+
/** Query comment for server-side profiling. */
|
|
362
|
+
comment?: string;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export interface BatchErrorRecord {
|
|
366
|
+
batchIndex: number;
|
|
367
|
+
message: string;
|
|
368
|
+
/** Additional error details. */
|
|
369
|
+
details?: unknown;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface InsertBatchResult {
|
|
373
|
+
acknowledged: boolean;
|
|
374
|
+
/** Total document count processed (never null for insert). */
|
|
375
|
+
totalCount: number;
|
|
376
|
+
insertedCount: number;
|
|
377
|
+
batchCount: number;
|
|
378
|
+
errors: BatchErrorRecord[];
|
|
379
|
+
insertedIds: Record<number, unknown>;
|
|
380
|
+
/** Per-batch retry records. */
|
|
381
|
+
retries: BatchRetryRecord[];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface UpdateBatchResult {
|
|
385
|
+
acknowledged: boolean;
|
|
386
|
+
totalCount: number | null;
|
|
387
|
+
matchedCount: number;
|
|
388
|
+
modifiedCount: number;
|
|
389
|
+
/** Number of documents upserted across all batches. */
|
|
390
|
+
upsertedCount: number;
|
|
391
|
+
batchCount: number;
|
|
392
|
+
errors: BatchErrorRecord[];
|
|
393
|
+
/** Per-batch retry records. */
|
|
394
|
+
retries: BatchRetryRecord[];
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface DeleteBatchResult {
|
|
398
|
+
acknowledged: boolean;
|
|
399
|
+
totalCount: number | null;
|
|
400
|
+
deletedCount: number;
|
|
401
|
+
batchCount: number;
|
|
402
|
+
errors: BatchErrorRecord[];
|
|
403
|
+
/** Per-batch retry records. */
|
|
404
|
+
retries: BatchRetryRecord[];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export interface BatchWriteOptions {
|
|
408
|
+
batchSize?: number;
|
|
409
|
+
ordered?: boolean;
|
|
410
|
+
concurrency?: number;
|
|
411
|
+
onProgress?: (progress: BatchProgress) => void;
|
|
412
|
+
onError?: 'stop' | 'skip' | 'collect' | 'retry';
|
|
413
|
+
retryAttempts?: number;
|
|
414
|
+
retryDelay?: number;
|
|
415
|
+
onRetry?: (retryInfo: RetryInfo) => void;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Options for updateBatch operations. */
|
|
419
|
+
export interface UpdateBatchOptions {
|
|
420
|
+
/** Number of documents per batch (default: 1000). */
|
|
421
|
+
batchSize?: number;
|
|
422
|
+
/** Estimate total for progress reporting. */
|
|
423
|
+
estimateProgress?: boolean;
|
|
424
|
+
/** Progress callback invoked after each batch. */
|
|
425
|
+
onProgress?: (progress: BatchProgress) => void;
|
|
426
|
+
/** Error handling strategy. */
|
|
427
|
+
onError?: 'stop' | 'skip' | 'collect' | 'retry';
|
|
428
|
+
/** Number of retry attempts per batch on transient failure. */
|
|
429
|
+
retryAttempts?: number;
|
|
430
|
+
/** Delay between retries in milliseconds. */
|
|
431
|
+
retryDelay?: number;
|
|
432
|
+
/** Retry callback invoked before each retry attempt. */
|
|
433
|
+
onRetry?: (retryInfo: RetryInfo) => void;
|
|
434
|
+
/** MongoDB write concern. */
|
|
435
|
+
writeConcern?: WriteConcern;
|
|
436
|
+
/** Upsert documents that do not match the filter. */
|
|
437
|
+
upsert?: boolean;
|
|
438
|
+
/** Array filters for nested array updates. */
|
|
439
|
+
arrayFilters?: unknown[];
|
|
440
|
+
/** Query comment for server-side profiling. */
|
|
441
|
+
comment?: string;
|
|
442
|
+
/** Sort order used to paginate through batch cursor. */
|
|
443
|
+
sort?: Record<string, 1 | -1>;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export interface IncrementOneOptions extends Record<string, unknown> {
|
|
447
|
+
returnDocument?: 'before' | 'after';
|
|
448
|
+
projection?: Record<string, unknown>;
|
|
449
|
+
$set?: Record<string, unknown>;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Result returned by {@link Collection.incrementOne}.
|
|
454
|
+
* The updated document is available via `.value` (or `null` if not found).
|
|
455
|
+
*/
|
|
456
|
+
export interface IncrementOneResult<TSchema = unknown> {
|
|
457
|
+
acknowledged: boolean;
|
|
458
|
+
matchedCount: number;
|
|
459
|
+
modifiedCount: number;
|
|
460
|
+
/** The document after the increment (or null when no match). */
|
|
461
|
+
value: TSchema | null;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export interface IndexCreateResult {
|
|
465
|
+
name: string;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export interface BookmarkPrewarmResult {
|
|
469
|
+
warmed: number;
|
|
470
|
+
failed: number;
|
|
471
|
+
keys: string[];
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export interface BookmarkListResult {
|
|
475
|
+
count: number;
|
|
476
|
+
pages: number[];
|
|
477
|
+
keys: string[];
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export interface BookmarkClearResult {
|
|
481
|
+
cleared: number;
|
|
482
|
+
pattern: string;
|
|
483
|
+
keysBefore: number;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export interface BookmarkKeyDims<TSchema = unknown> extends Omit<FindPageOptions<TSchema>, 'page'> { }
|
|
487
|
+
|
|
488
|
+
export interface BookmarkCacheLike {
|
|
489
|
+
set(key: string, value: unknown): void | boolean | Promise<void> | Promise<boolean>;
|
|
490
|
+
get(key: string): unknown | Promise<unknown>;
|
|
491
|
+
delete?(key: string): boolean | Promise<boolean>;
|
|
492
|
+
keys?(pattern: string): string[] | Promise<string[]>;
|
|
493
|
+
delPattern?(pattern: string): number | Promise<number>;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export interface AdminBuildInfoView {
|
|
497
|
+
version?: string;
|
|
498
|
+
versionArray?: number[];
|
|
499
|
+
gitVersion?: string;
|
|
500
|
+
bits?: number;
|
|
501
|
+
debug?: boolean;
|
|
502
|
+
maxBsonObjectSize?: number;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
export interface ServerStatusView {
|
|
506
|
+
connections: {
|
|
507
|
+
current?: number;
|
|
508
|
+
available?: number;
|
|
509
|
+
totalCreated?: number;
|
|
510
|
+
};
|
|
511
|
+
mem: {
|
|
512
|
+
resident?: number;
|
|
513
|
+
virtual?: number;
|
|
514
|
+
mapped?: number;
|
|
515
|
+
};
|
|
516
|
+
opcounters: {
|
|
517
|
+
insert?: number;
|
|
518
|
+
query?: number;
|
|
519
|
+
update?: number;
|
|
520
|
+
delete?: number;
|
|
521
|
+
getmore?: number;
|
|
522
|
+
command?: number;
|
|
523
|
+
};
|
|
524
|
+
network: {
|
|
525
|
+
bytesIn?: number;
|
|
526
|
+
bytesOut?: number;
|
|
527
|
+
numRequests?: number;
|
|
528
|
+
};
|
|
529
|
+
uptime?: number;
|
|
530
|
+
localTime?: Date;
|
|
531
|
+
version?: string;
|
|
532
|
+
process?: string;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
export interface DbStatsView {
|
|
536
|
+
db?: string;
|
|
537
|
+
collections?: number;
|
|
538
|
+
views?: number;
|
|
539
|
+
objects?: number;
|
|
540
|
+
avgObjSize?: number;
|
|
541
|
+
dataSize?: number;
|
|
542
|
+
storageSize?: number;
|
|
543
|
+
indexes?: number;
|
|
544
|
+
indexSize?: number;
|
|
545
|
+
totalSize?: number;
|
|
546
|
+
scaleFactor?: number;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export interface AdminAccessor {
|
|
550
|
+
/** Pings the MongoDB server and returns true when reachable. */
|
|
551
|
+
ping(): Promise<boolean>;
|
|
552
|
+
/** Returns MongoDB server build information. */
|
|
553
|
+
buildInfo(): Promise<AdminBuildInfoView>;
|
|
554
|
+
/**
|
|
555
|
+
* Returns current server status metrics.
|
|
556
|
+
* @param options - Optional scale factor for byte values.
|
|
557
|
+
* @returns Server status snapshot.
|
|
558
|
+
*/
|
|
559
|
+
serverStatus(options?: { scale?: number; }): Promise<ServerStatusView>;
|
|
560
|
+
/**
|
|
561
|
+
* Returns database storage statistics.
|
|
562
|
+
* @param options - Optional scale factor for byte values.
|
|
563
|
+
* @returns Database stats view.
|
|
564
|
+
*/
|
|
565
|
+
stats(options?: { scale?: number; }): Promise<DbStatsView>;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
568
|
export interface Collection<TSchema = any> {
|
|
569
|
-
/** Returns the namespace descriptor (iid, db, collection) for this collection. */
|
|
570
|
-
getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; };
|
|
571
|
-
/** Returns the underlying native MongoDB Collection object. */
|
|
572
|
-
raw(): unknown;
|
|
573
|
-
/**
|
|
574
|
-
* Finds the first document matching the query.
|
|
575
|
-
* @param query - MongoDB filter query.
|
|
576
|
-
* @param options - MongoDB FindOptions.
|
|
577
|
-
* @returns The matched document, or null when not found.
|
|
578
|
-
*/
|
|
569
|
+
/** Returns the namespace descriptor (iid, db, collection) for this collection. */
|
|
570
|
+
getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; };
|
|
571
|
+
/** Returns the underlying native MongoDB Collection object. */
|
|
572
|
+
raw(): unknown;
|
|
573
|
+
/**
|
|
574
|
+
* Finds the first document matching the query.
|
|
575
|
+
* @param query - MongoDB filter query.
|
|
576
|
+
* @param options - MongoDB FindOptions.
|
|
577
|
+
* @returns The matched document, or null when not found.
|
|
578
|
+
*/
|
|
579
579
|
findOne(query: unknown | undefined, options: QueryMetaOption): Promise<ResultWithMeta<TSchema | null>>;
|
|
580
580
|
findOne(query?: unknown, options?: unknown): Promise<TSchema | null>;
|
|
581
|
-
/**
|
|
582
|
-
* Returns a chainable cursor over documents matching the query.
|
|
583
|
-
* @param query - MongoDB filter query.
|
|
584
|
-
* @param options - MongoDB FindOptions.
|
|
585
|
-
* @returns A chainable FindChain that resolves to an array.
|
|
586
|
-
*/
|
|
581
|
+
/**
|
|
582
|
+
* Returns a chainable cursor over documents matching the query.
|
|
583
|
+
* @param query - MongoDB filter query.
|
|
584
|
+
* @param options - MongoDB FindOptions.
|
|
585
|
+
* @returns A chainable FindChain that resolves to an array.
|
|
586
|
+
*/
|
|
587
587
|
find(query: unknown | undefined, options: QueryMetaOption): FindChain<TSchema, ResultWithMeta<TSchema[]>>;
|
|
588
588
|
find(query: unknown | undefined, projection: unknown, options?: unknown): FindChain<TSchema>;
|
|
589
589
|
find(query?: unknown, options?: unknown): FindChain<TSchema>;
|
|
590
|
-
/**
|
|
591
|
-
* Finds a single document by its `_id` value.
|
|
592
|
-
* @param id - The `_id` value to look up.
|
|
593
|
-
* @param options - MongoDB FindOptions.
|
|
594
|
-
* @returns The matched document, or null when not found.
|
|
595
|
-
*/
|
|
596
|
-
findOneById(id: unknown, options?: unknown): Promise<TSchema | null>;
|
|
597
|
-
/**
|
|
598
|
-
* Fetches multiple documents by their `_id` values in a single query.
|
|
599
|
-
* @param ids - Array of `_id` values to look up.
|
|
600
|
-
* @param options - MongoDB FindOptions.
|
|
601
|
-
* @returns Array of matched documents (order not guaranteed).
|
|
602
|
-
*/
|
|
603
|
-
findByIds(ids: unknown[], options?: unknown): Promise<TSchema[]>;
|
|
604
|
-
/**
|
|
605
|
-
* Finds documents matching the query and returns both the data array and
|
|
606
|
-
* the total count unaffected by limit/skip.
|
|
607
|
-
* @param query - MongoDB filter query.
|
|
608
|
-
* @param options - MongoDB FindOptions.
|
|
609
|
-
* @returns Object with `data` array and `total` count.
|
|
610
|
-
*/
|
|
611
|
-
findAndCount(query?: unknown, options?: unknown): Promise<FindAndCountResult<TSchema>>;
|
|
612
|
-
/**
|
|
613
|
-
* Returns a Node.js ReadableStream of documents matching the query.
|
|
614
|
-
* @param query - MongoDB filter query.
|
|
615
|
-
* @param options - StreamOptions (projection, sort, limit, batchSize, …).
|
|
616
|
-
* @returns Readable object-mode stream emitting one document per chunk.
|
|
617
|
-
*/
|
|
618
|
-
stream(query?: unknown, options?: unknown): NodeJS.ReadableStream;
|
|
619
|
-
/**
|
|
620
|
-
* Returns the MongoDB query execution plan without running the full query.
|
|
621
|
-
* @param query - MongoDB filter query.
|
|
622
|
-
* @param options - ExplainOptions including verbosity level.
|
|
623
|
-
* @returns Raw explain output from MongoDB.
|
|
624
|
-
*/
|
|
625
|
-
explain(query?: unknown, options?: unknown): Promise<unknown>;
|
|
626
|
-
/**
|
|
627
|
-
* Counts documents matching the query.
|
|
628
|
-
* @param query - MongoDB filter query.
|
|
629
|
-
* @param options - MongoDB CountDocumentsOptions.
|
|
630
|
-
* @returns Number of matched documents.
|
|
631
|
-
*/
|
|
632
|
-
count(query: unknown | undefined, options: QueryMetaOption): Promise<ResultWithMeta<number>>;
|
|
633
|
-
count(query?: unknown, options?: unknown): Promise<number>;
|
|
634
|
-
/**
|
|
635
|
-
* Inserts a single document into the collection.
|
|
636
|
-
* @param document - Document to insert.
|
|
637
|
-
* @param options - InsertOneSimplifiedOptions or InsertOneOptions.
|
|
638
|
-
* @returns Acknowledged result with the inserted `_id`.
|
|
639
|
-
* @since v1.0.0
|
|
640
|
-
*/
|
|
641
|
-
insertOne(document?: unknown, options?: unknown): Promise<InsertOneResult>;
|
|
642
|
-
/**
|
|
643
|
-
* Inserts multiple documents into the collection in a single operation.
|
|
644
|
-
* @param documents - Array of documents to insert.
|
|
645
|
-
* @param options - InsertManySimplifiedOptions or InsertManyOptions.
|
|
646
|
-
* @returns Acknowledged result with inserted count and `_id` map.
|
|
647
|
-
* @since v1.0.0
|
|
648
|
-
*/
|
|
649
|
-
insertMany(documents?: unknown[], options?: unknown): Promise<InsertManyResult>;
|
|
650
|
-
/**
|
|
651
|
-
* Updates the first document matching the filter.
|
|
652
|
-
* @param filter - MongoDB filter query.
|
|
653
|
-
* @param update - Update operators (e.g. `$set`, `$inc`).
|
|
654
|
-
* @param options - MongoDB UpdateOptions.
|
|
655
|
-
* @returns Update result with matched/modified counts.
|
|
656
|
-
* @since v1.0.0
|
|
657
|
-
*/
|
|
658
|
-
updateOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
659
|
-
/**
|
|
660
|
-
* Updates all documents matching the filter.
|
|
661
|
-
* @param filter - MongoDB filter query.
|
|
662
|
-
* @param update - Update operators.
|
|
663
|
-
* @param options - MongoDB UpdateOptions.
|
|
664
|
-
* @returns Update result with matched/modified counts.
|
|
665
|
-
* @since v1.0.0
|
|
666
|
-
*/
|
|
667
|
-
updateMany(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
668
|
-
/**
|
|
669
|
-
* Replaces the first document matching the filter with a new document.
|
|
670
|
-
* @param filter - MongoDB filter query.
|
|
671
|
-
* @param replacement - Full replacement document (no update operators).
|
|
672
|
-
* @param options - MongoDB ReplaceOptions.
|
|
673
|
-
* @returns Update result indicating match and modification.
|
|
674
|
-
* @since v1.0.0
|
|
675
|
-
*/
|
|
676
|
-
replaceOne(filter?: unknown, replacement?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
677
|
-
/**
|
|
678
|
-
* Atomically finds the first matching document, replaces it, and returns a document.
|
|
679
|
-
* @param filter - MongoDB filter query.
|
|
680
|
-
* @param replacement - Full replacement document.
|
|
681
|
-
* @param options - MongoDB FindOneAndReplaceOptions.
|
|
682
|
-
* @returns The document before or after replacement, or null when not found.
|
|
683
|
-
* @since v1.0.0
|
|
684
|
-
*/
|
|
685
|
-
findOneAndReplace(filter?: unknown, replacement?: unknown, options?: unknown): Promise<TSchema | null>;
|
|
686
|
-
/**
|
|
687
|
-
* Atomically finds the first matching document, applies an update, and returns a document.
|
|
688
|
-
* @param filter - MongoDB filter query.
|
|
689
|
-
* @param update - Update operators.
|
|
690
|
-
* @param options - MongoDB FindOneAndUpdateOptions.
|
|
691
|
-
* @returns The document before or after the update, or null when not found.
|
|
692
|
-
* @since v1.0.0
|
|
693
|
-
*/
|
|
694
|
-
findOneAndUpdate(filter?: unknown, update?: unknown, options?: unknown): Promise<TSchema | null>;
|
|
695
|
-
/**
|
|
696
|
-
* Atomically finds the first matching document, deletes it, and returns it.
|
|
697
|
-
* @param filter - MongoDB filter query.
|
|
698
|
-
* @param options - MongoDB FindOneAndDeleteOptions.
|
|
699
|
-
* @returns The deleted document, or null when not found.
|
|
700
|
-
* @since v1.0.0
|
|
701
|
-
*/
|
|
702
|
-
findOneAndDelete(filter?: unknown, options?: unknown): Promise<TSchema | null>;
|
|
703
|
-
/**
|
|
704
|
-
* Updates the first matching document or inserts it when no match exists.
|
|
705
|
-
* @param filter - MongoDB filter query.
|
|
706
|
-
* @param update - Update operators.
|
|
707
|
-
* @param options - MongoDB UpdateOptions (upsert is forced true).
|
|
708
|
-
* @returns Update result; `upsertedId` is set when a new document was inserted.
|
|
709
|
-
* @since v1.0.0
|
|
710
|
-
*/
|
|
711
|
-
upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
712
|
-
/**
|
|
713
|
-
* Deletes the first document matching the filter.
|
|
714
|
-
* @param filter - MongoDB filter query.
|
|
715
|
-
* @param options - MongoDB DeleteOptions.
|
|
716
|
-
* @returns Delete result with the deleted document count.
|
|
717
|
-
* @since v1.0.0
|
|
718
|
-
*/
|
|
719
|
-
deleteOne(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
720
|
-
/**
|
|
721
|
-
* Deletes all documents matching the filter.
|
|
722
|
-
* @param filter - MongoDB filter query.
|
|
723
|
-
* @param options - MongoDB DeleteOptions.
|
|
724
|
-
* @returns Delete result with the total deleted count.
|
|
725
|
-
* @since v1.0.0
|
|
726
|
-
*/
|
|
727
|
-
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
728
|
-
/**
|
|
729
|
-
* Inserts a large document array in configurable batches with progress and retry support.
|
|
730
|
-
* @param documents - Documents to insert.
|
|
731
|
-
* @param options - InsertBatchOptions (batchSize, concurrency, onProgress, …).
|
|
732
|
-
* @returns Aggregated insert result across all batches.
|
|
733
|
-
* @since v1.2.0
|
|
734
|
-
*/
|
|
735
|
-
insertBatch(documents?: unknown[], options?: unknown): Promise<InsertBatchResult>;
|
|
736
|
-
/**
|
|
737
|
-
* Updates matched documents in configurable batches, walking via a cursor.
|
|
738
|
-
* @param filter - MongoDB filter query.
|
|
739
|
-
* @param update - Update operators.
|
|
740
|
-
* @param options - UpdateBatchOptions (batchSize, upsert, onProgress, …).
|
|
741
|
-
* @returns Aggregated update result across all batches.
|
|
742
|
-
* @since v1.2.0
|
|
743
|
-
*/
|
|
744
|
-
updateBatch(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateBatchResult>;
|
|
745
|
-
/**
|
|
746
|
-
* Deletes matched documents in configurable batches.
|
|
747
|
-
* @param filter - MongoDB filter query.
|
|
748
|
-
* @param options - DeleteBatchOptions (batchSize, onProgress, …).
|
|
749
|
-
* @returns Aggregated delete result across all batches.
|
|
750
|
-
* @since v1.2.0
|
|
751
|
-
*/
|
|
752
|
-
deleteBatch(filter?: unknown, options?: unknown): Promise<DeleteBatchResult>;
|
|
753
|
-
/**
|
|
754
|
-
* Atomically increments a numeric field on the first matching document.
|
|
755
|
-
* @param filter - MongoDB filter query.
|
|
756
|
-
* @param field - Field name (string) or a `{ field: delta }` map for multi-field increments.
|
|
757
|
-
* @param incrementOrOptions - Numeric delta when `field` is a string, or IncrementOneOptions.
|
|
758
|
-
* @param maybeOptions - IncrementOneOptions when the third argument is the delta.
|
|
759
|
-
* @returns Result containing matched/modified counts and the returned document value.
|
|
760
|
-
* @since v1.1.0
|
|
761
|
-
*/
|
|
762
|
-
incrementOne(filter?: unknown, field?: string | Record<string, number>, incrementOrOptions?: unknown, maybeOptions?: unknown): Promise<IncrementOneResult<TSchema>>;
|
|
763
|
-
/**
|
|
764
|
-
* Creates a single index on the collection.
|
|
765
|
-
* @param keys - Index key specification.
|
|
766
|
-
* @param options - MongoDB CreateIndexesOptions (name, unique, sparse, …).
|
|
767
|
-
* @returns Object containing the created index name.
|
|
768
|
-
* @since v1.0.0
|
|
769
|
-
*/
|
|
770
|
-
createIndex(keys: unknown, options?: unknown): Promise<IndexCreateResult>;
|
|
771
|
-
/**
|
|
772
|
-
* Creates multiple indexes on the collection in one operation.
|
|
773
|
-
* @param specs - Array of index specifications (each must include a `key` field).
|
|
774
|
-
* @returns Array of created index names.
|
|
775
|
-
* @since v1.0.0
|
|
776
|
-
*/
|
|
777
|
-
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
778
|
-
/**
|
|
779
|
-
* Lists all indexes defined on the collection.
|
|
780
|
-
* @returns Array of index descriptor objects as returned by MongoDB.
|
|
781
|
-
*/
|
|
782
|
-
listIndexes(): Promise<Record<string, unknown>[]>;
|
|
783
|
-
/**
|
|
784
|
-
* Drops the named index from the collection.
|
|
785
|
-
* @param name - The index name to drop.
|
|
786
|
-
* @since v1.0.0
|
|
787
|
-
*/
|
|
788
|
-
dropIndex(name: string): Promise<unknown>;
|
|
789
|
-
/**
|
|
790
|
-
* Drops all non-`_id` indexes from the collection.
|
|
791
|
-
* @since v1.0.0
|
|
792
|
-
*/
|
|
793
|
-
dropIndexes(): Promise<unknown>;
|
|
794
|
-
prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise<BookmarkPrewarmResult>;
|
|
795
|
-
listBookmarks(keyDims?: unknown): Promise<BookmarkListResult>;
|
|
796
|
-
clearBookmarks(keyDims?: unknown): Promise<BookmarkClearResult>;
|
|
797
|
-
/**
|
|
798
|
-
* Returns the distinct values for the specified field across matching documents.
|
|
799
|
-
* @param key - Field path to collect distinct values from.
|
|
800
|
-
* @param query - Optional MongoDB filter query.
|
|
801
|
-
* @param options - MongoDB DistinctOptions.
|
|
802
|
-
* @returns Array of unique field values.
|
|
803
|
-
*/
|
|
804
|
-
distinct(key: string, query: unknown | undefined, options: QueryMetaOption): Promise<ResultWithMeta<unknown[]>>;
|
|
805
|
-
distinct(key: string, query?: unknown, options?: unknown): Promise<unknown[]>;
|
|
806
|
-
/**
|
|
807
|
-
* Builds and executes an aggregation pipeline, returning a chainable object.
|
|
808
|
-
* @param pipeline - Array of aggregation stage documents.
|
|
809
|
-
* @param options - MongoDB AggregateOptions.
|
|
810
|
-
* @returns AggregateChain that resolves to the result array.
|
|
811
|
-
*/
|
|
812
|
-
aggregate<TResult = unknown>(pipeline: unknown[] | undefined, options: QueryMetaOption): AggregateChain<TResult, ResultWithMeta<TResult[]>>;
|
|
813
|
-
aggregate<TResult = unknown>(pipeline?: unknown[], options?: unknown): AggregateChain<TResult>;
|
|
590
|
+
/**
|
|
591
|
+
* Finds a single document by its `_id` value.
|
|
592
|
+
* @param id - The `_id` value to look up.
|
|
593
|
+
* @param options - MongoDB FindOptions.
|
|
594
|
+
* @returns The matched document, or null when not found.
|
|
595
|
+
*/
|
|
596
|
+
findOneById(id: unknown, options?: unknown): Promise<TSchema | null>;
|
|
597
|
+
/**
|
|
598
|
+
* Fetches multiple documents by their `_id` values in a single query.
|
|
599
|
+
* @param ids - Array of `_id` values to look up.
|
|
600
|
+
* @param options - MongoDB FindOptions.
|
|
601
|
+
* @returns Array of matched documents (order not guaranteed).
|
|
602
|
+
*/
|
|
603
|
+
findByIds(ids: unknown[], options?: unknown): Promise<TSchema[]>;
|
|
604
|
+
/**
|
|
605
|
+
* Finds documents matching the query and returns both the data array and
|
|
606
|
+
* the total count unaffected by limit/skip.
|
|
607
|
+
* @param query - MongoDB filter query.
|
|
608
|
+
* @param options - MongoDB FindOptions.
|
|
609
|
+
* @returns Object with `data` array and `total` count.
|
|
610
|
+
*/
|
|
611
|
+
findAndCount(query?: unknown, options?: unknown): Promise<FindAndCountResult<TSchema>>;
|
|
612
|
+
/**
|
|
613
|
+
* Returns a Node.js ReadableStream of documents matching the query.
|
|
614
|
+
* @param query - MongoDB filter query.
|
|
615
|
+
* @param options - StreamOptions (projection, sort, limit, batchSize, …).
|
|
616
|
+
* @returns Readable object-mode stream emitting one document per chunk.
|
|
617
|
+
*/
|
|
618
|
+
stream(query?: unknown, options?: unknown): NodeJS.ReadableStream;
|
|
619
|
+
/**
|
|
620
|
+
* Returns the MongoDB query execution plan without running the full query.
|
|
621
|
+
* @param query - MongoDB filter query.
|
|
622
|
+
* @param options - ExplainOptions including verbosity level.
|
|
623
|
+
* @returns Raw explain output from MongoDB.
|
|
624
|
+
*/
|
|
625
|
+
explain(query?: unknown, options?: unknown): Promise<unknown>;
|
|
626
|
+
/**
|
|
627
|
+
* Counts documents matching the query.
|
|
628
|
+
* @param query - MongoDB filter query.
|
|
629
|
+
* @param options - MongoDB CountDocumentsOptions.
|
|
630
|
+
* @returns Number of matched documents.
|
|
631
|
+
*/
|
|
632
|
+
count(query: unknown | undefined, options: QueryMetaOption): Promise<ResultWithMeta<number>>;
|
|
633
|
+
count(query?: unknown, options?: unknown): Promise<number>;
|
|
634
|
+
/**
|
|
635
|
+
* Inserts a single document into the collection.
|
|
636
|
+
* @param document - Document to insert.
|
|
637
|
+
* @param options - InsertOneSimplifiedOptions or InsertOneOptions.
|
|
638
|
+
* @returns Acknowledged result with the inserted `_id`.
|
|
639
|
+
* @since v1.0.0
|
|
640
|
+
*/
|
|
641
|
+
insertOne(document?: unknown, options?: unknown): Promise<InsertOneResult>;
|
|
642
|
+
/**
|
|
643
|
+
* Inserts multiple documents into the collection in a single operation.
|
|
644
|
+
* @param documents - Array of documents to insert.
|
|
645
|
+
* @param options - InsertManySimplifiedOptions or InsertManyOptions.
|
|
646
|
+
* @returns Acknowledged result with inserted count and `_id` map.
|
|
647
|
+
* @since v1.0.0
|
|
648
|
+
*/
|
|
649
|
+
insertMany(documents?: unknown[], options?: unknown): Promise<InsertManyResult>;
|
|
650
|
+
/**
|
|
651
|
+
* Updates the first document matching the filter.
|
|
652
|
+
* @param filter - MongoDB filter query.
|
|
653
|
+
* @param update - Update operators (e.g. `$set`, `$inc`).
|
|
654
|
+
* @param options - MongoDB UpdateOptions.
|
|
655
|
+
* @returns Update result with matched/modified counts.
|
|
656
|
+
* @since v1.0.0
|
|
657
|
+
*/
|
|
658
|
+
updateOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
659
|
+
/**
|
|
660
|
+
* Updates all documents matching the filter.
|
|
661
|
+
* @param filter - MongoDB filter query.
|
|
662
|
+
* @param update - Update operators.
|
|
663
|
+
* @param options - MongoDB UpdateOptions.
|
|
664
|
+
* @returns Update result with matched/modified counts.
|
|
665
|
+
* @since v1.0.0
|
|
666
|
+
*/
|
|
667
|
+
updateMany(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
668
|
+
/**
|
|
669
|
+
* Replaces the first document matching the filter with a new document.
|
|
670
|
+
* @param filter - MongoDB filter query.
|
|
671
|
+
* @param replacement - Full replacement document (no update operators).
|
|
672
|
+
* @param options - MongoDB ReplaceOptions.
|
|
673
|
+
* @returns Update result indicating match and modification.
|
|
674
|
+
* @since v1.0.0
|
|
675
|
+
*/
|
|
676
|
+
replaceOne(filter?: unknown, replacement?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
677
|
+
/**
|
|
678
|
+
* Atomically finds the first matching document, replaces it, and returns a document.
|
|
679
|
+
* @param filter - MongoDB filter query.
|
|
680
|
+
* @param replacement - Full replacement document.
|
|
681
|
+
* @param options - MongoDB FindOneAndReplaceOptions.
|
|
682
|
+
* @returns The document before or after replacement, or null when not found.
|
|
683
|
+
* @since v1.0.0
|
|
684
|
+
*/
|
|
685
|
+
findOneAndReplace(filter?: unknown, replacement?: unknown, options?: unknown): Promise<TSchema | null>;
|
|
686
|
+
/**
|
|
687
|
+
* Atomically finds the first matching document, applies an update, and returns a document.
|
|
688
|
+
* @param filter - MongoDB filter query.
|
|
689
|
+
* @param update - Update operators.
|
|
690
|
+
* @param options - MongoDB FindOneAndUpdateOptions.
|
|
691
|
+
* @returns The document before or after the update, or null when not found.
|
|
692
|
+
* @since v1.0.0
|
|
693
|
+
*/
|
|
694
|
+
findOneAndUpdate(filter?: unknown, update?: unknown, options?: unknown): Promise<TSchema | null>;
|
|
695
|
+
/**
|
|
696
|
+
* Atomically finds the first matching document, deletes it, and returns it.
|
|
697
|
+
* @param filter - MongoDB filter query.
|
|
698
|
+
* @param options - MongoDB FindOneAndDeleteOptions.
|
|
699
|
+
* @returns The deleted document, or null when not found.
|
|
700
|
+
* @since v1.0.0
|
|
701
|
+
*/
|
|
702
|
+
findOneAndDelete(filter?: unknown, options?: unknown): Promise<TSchema | null>;
|
|
703
|
+
/**
|
|
704
|
+
* Updates the first matching document or inserts it when no match exists.
|
|
705
|
+
* @param filter - MongoDB filter query.
|
|
706
|
+
* @param update - Update operators.
|
|
707
|
+
* @param options - MongoDB UpdateOptions (upsert is forced true).
|
|
708
|
+
* @returns Update result; `upsertedId` is set when a new document was inserted.
|
|
709
|
+
* @since v1.0.0
|
|
710
|
+
*/
|
|
711
|
+
upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
712
|
+
/**
|
|
713
|
+
* Deletes the first document matching the filter.
|
|
714
|
+
* @param filter - MongoDB filter query.
|
|
715
|
+
* @param options - MongoDB DeleteOptions.
|
|
716
|
+
* @returns Delete result with the deleted document count.
|
|
717
|
+
* @since v1.0.0
|
|
718
|
+
*/
|
|
719
|
+
deleteOne(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
720
|
+
/**
|
|
721
|
+
* Deletes all documents matching the filter.
|
|
722
|
+
* @param filter - MongoDB filter query.
|
|
723
|
+
* @param options - MongoDB DeleteOptions.
|
|
724
|
+
* @returns Delete result with the total deleted count.
|
|
725
|
+
* @since v1.0.0
|
|
726
|
+
*/
|
|
727
|
+
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
728
|
+
/**
|
|
729
|
+
* Inserts a large document array in configurable batches with progress and retry support.
|
|
730
|
+
* @param documents - Documents to insert.
|
|
731
|
+
* @param options - InsertBatchOptions (batchSize, concurrency, onProgress, …).
|
|
732
|
+
* @returns Aggregated insert result across all batches.
|
|
733
|
+
* @since v1.2.0
|
|
734
|
+
*/
|
|
735
|
+
insertBatch(documents?: unknown[], options?: unknown): Promise<InsertBatchResult>;
|
|
736
|
+
/**
|
|
737
|
+
* Updates matched documents in configurable batches, walking via a cursor.
|
|
738
|
+
* @param filter - MongoDB filter query.
|
|
739
|
+
* @param update - Update operators.
|
|
740
|
+
* @param options - UpdateBatchOptions (batchSize, upsert, onProgress, …).
|
|
741
|
+
* @returns Aggregated update result across all batches.
|
|
742
|
+
* @since v1.2.0
|
|
743
|
+
*/
|
|
744
|
+
updateBatch(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateBatchResult>;
|
|
745
|
+
/**
|
|
746
|
+
* Deletes matched documents in configurable batches.
|
|
747
|
+
* @param filter - MongoDB filter query.
|
|
748
|
+
* @param options - DeleteBatchOptions (batchSize, onProgress, …).
|
|
749
|
+
* @returns Aggregated delete result across all batches.
|
|
750
|
+
* @since v1.2.0
|
|
751
|
+
*/
|
|
752
|
+
deleteBatch(filter?: unknown, options?: unknown): Promise<DeleteBatchResult>;
|
|
753
|
+
/**
|
|
754
|
+
* Atomically increments a numeric field on the first matching document.
|
|
755
|
+
* @param filter - MongoDB filter query.
|
|
756
|
+
* @param field - Field name (string) or a `{ field: delta }` map for multi-field increments.
|
|
757
|
+
* @param incrementOrOptions - Numeric delta when `field` is a string, or IncrementOneOptions.
|
|
758
|
+
* @param maybeOptions - IncrementOneOptions when the third argument is the delta.
|
|
759
|
+
* @returns Result containing matched/modified counts and the returned document value.
|
|
760
|
+
* @since v1.1.0
|
|
761
|
+
*/
|
|
762
|
+
incrementOne(filter?: unknown, field?: string | Record<string, number>, incrementOrOptions?: unknown, maybeOptions?: unknown): Promise<IncrementOneResult<TSchema>>;
|
|
763
|
+
/**
|
|
764
|
+
* Creates a single index on the collection.
|
|
765
|
+
* @param keys - Index key specification.
|
|
766
|
+
* @param options - MongoDB CreateIndexesOptions (name, unique, sparse, …).
|
|
767
|
+
* @returns Object containing the created index name.
|
|
768
|
+
* @since v1.0.0
|
|
769
|
+
*/
|
|
770
|
+
createIndex(keys: unknown, options?: unknown): Promise<IndexCreateResult>;
|
|
771
|
+
/**
|
|
772
|
+
* Creates multiple indexes on the collection in one operation.
|
|
773
|
+
* @param specs - Array of index specifications (each must include a `key` field).
|
|
774
|
+
* @returns Array of created index names.
|
|
775
|
+
* @since v1.0.0
|
|
776
|
+
*/
|
|
777
|
+
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
778
|
+
/**
|
|
779
|
+
* Lists all indexes defined on the collection.
|
|
780
|
+
* @returns Array of index descriptor objects as returned by MongoDB.
|
|
781
|
+
*/
|
|
782
|
+
listIndexes(): Promise<Record<string, unknown>[]>;
|
|
783
|
+
/**
|
|
784
|
+
* Drops the named index from the collection.
|
|
785
|
+
* @param name - The index name to drop.
|
|
786
|
+
* @since v1.0.0
|
|
787
|
+
*/
|
|
788
|
+
dropIndex(name: string): Promise<unknown>;
|
|
789
|
+
/**
|
|
790
|
+
* Drops all non-`_id` indexes from the collection.
|
|
791
|
+
* @since v1.0.0
|
|
792
|
+
*/
|
|
793
|
+
dropIndexes(): Promise<unknown>;
|
|
794
|
+
prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise<BookmarkPrewarmResult>;
|
|
795
|
+
listBookmarks(keyDims?: unknown): Promise<BookmarkListResult>;
|
|
796
|
+
clearBookmarks(keyDims?: unknown): Promise<BookmarkClearResult>;
|
|
797
|
+
/**
|
|
798
|
+
* Returns the distinct values for the specified field across matching documents.
|
|
799
|
+
* @param key - Field path to collect distinct values from.
|
|
800
|
+
* @param query - Optional MongoDB filter query.
|
|
801
|
+
* @param options - MongoDB DistinctOptions.
|
|
802
|
+
* @returns Array of unique field values.
|
|
803
|
+
*/
|
|
804
|
+
distinct(key: string, query: unknown | undefined, options: QueryMetaOption): Promise<ResultWithMeta<unknown[]>>;
|
|
805
|
+
distinct(key: string, query?: unknown, options?: unknown): Promise<unknown[]>;
|
|
806
|
+
/**
|
|
807
|
+
* Builds and executes an aggregation pipeline, returning a chainable object.
|
|
808
|
+
* @param pipeline - Array of aggregation stage documents.
|
|
809
|
+
* @param options - MongoDB AggregateOptions.
|
|
810
|
+
* @returns AggregateChain that resolves to the result array.
|
|
811
|
+
*/
|
|
812
|
+
aggregate<TResult = unknown>(pipeline: unknown[] | undefined, options: QueryMetaOption): AggregateChain<TResult, ResultWithMeta<TResult[]>>;
|
|
813
|
+
aggregate<TResult = unknown>(pipeline?: unknown[], options?: unknown): AggregateChain<TResult>;
|
|
814
814
|
/** Stream mode: returns a readable stream of page documents when `stream: true`. */
|
|
815
815
|
findPage(options: FindPageOptions<TSchema> & { stream: true }): NodeJS.ReadableStream;
|
|
816
816
|
/** Sync totals mode guarantees `totals.total` and `totals.totalPages` are immediately available. */
|
|
817
817
|
findPage(options: FindPageOptions<TSchema> & { totals: { mode: 'sync'; } & Record<string, unknown> }): Promise<Omit<FindPageResult<TSchema>, 'totals'> & { totals: LegacySyncTotalsInfo<TSchema> }>;
|
|
818
818
|
/** Returns a cursor-based paginated result set. */
|
|
819
819
|
findPage(options?: FindPageOptions<TSchema>): Promise<FindPageResult<TSchema>>;
|
|
820
|
-
/**
|
|
821
|
-
* Opens a MongoDB change stream to listen for collection-level change events.
|
|
822
|
-
* @param pipeline - Optional aggregation pipeline to filter/transform events.
|
|
823
|
-
* @param options - MongoDB ChangeStreamOptions.
|
|
824
|
-
* @returns A ChangeStream instance emitting change event documents.
|
|
825
|
-
*/
|
|
826
|
-
watch(pipeline?: unknown[], options?: unknown): ChangeStream;
|
|
827
|
-
/**
|
|
828
|
-
* Manually invalidates cached query results for the specified operation type.
|
|
829
|
-
* @param op - Operation whose cache entries to clear; omit to clear all.
|
|
830
|
-
* @returns Number of cache entries removed.
|
|
831
|
-
* @since v1.3.0
|
|
832
|
-
*/
|
|
833
|
-
invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise<number>;
|
|
834
|
-
/**
|
|
835
|
-
* Drops the entire collection from the database.
|
|
836
|
-
* @returns True when the collection was dropped successfully.
|
|
837
|
-
* @since v1.3.0
|
|
838
|
-
*/
|
|
839
|
-
dropCollection(): Promise<boolean>;
|
|
840
|
-
/**
|
|
841
|
-
* Creates a new collection (or capped collection) in the database.
|
|
842
|
-
* @param name - Collection name; defaults to the current collection name when omitted.
|
|
843
|
-
* @param options - MongoDB CreateCollectionOptions (capped, size, validator, …).
|
|
844
|
-
* @returns True when the collection was created successfully.
|
|
845
|
-
* @since v1.3.0
|
|
846
|
-
*/
|
|
847
|
-
createCollection(name?: string, options?: Record<string, unknown>): Promise<boolean>;
|
|
848
|
-
/**
|
|
849
|
-
* Creates a MongoDB view backed by an aggregation pipeline over a source collection.
|
|
850
|
-
* @param name - Name of the view to create.
|
|
851
|
-
* @param source - Name of the source collection.
|
|
852
|
-
* @param pipeline - Optional aggregation pipeline defining the view.
|
|
853
|
-
* @returns True when the view was created successfully.
|
|
854
|
-
* @since v1.3.0
|
|
855
|
-
*/
|
|
856
|
-
createView(name: string, source: string, pipeline?: unknown[]): Promise<boolean>;
|
|
857
|
-
/**
|
|
858
|
-
* Returns index usage statistics for all indexes on the collection.
|
|
859
|
-
* @returns Array of `$indexStats` documents from MongoDB.
|
|
860
|
-
* @since v1.3.0
|
|
861
|
-
*/
|
|
862
|
-
indexStats(): Promise<unknown[]>;
|
|
863
|
-
/**
|
|
864
|
-
* Sets the JSON Schema validator and optional validation settings.
|
|
865
|
-
* @since v1.3.0
|
|
866
|
-
*/
|
|
867
|
-
setValidator(validator: unknown, options?: { validationLevel?: string; validationAction?: string }): Promise<{ ok: number; collection: string }>;
|
|
868
|
-
/** Sets the collection validation level. @since v1.3.0 */
|
|
869
|
-
setValidationLevel(level: 'off' | 'moderate' | 'strict' | string): Promise<{ ok: number; validationLevel: string }>;
|
|
870
|
-
/** Sets the collection validation action. @since v1.3.0 */
|
|
871
|
-
setValidationAction(action: 'error' | 'warn' | string): Promise<{ ok: number; validationAction: string }>;
|
|
872
|
-
/** Reads the current collection validator and validation settings. @since v1.3.0 */
|
|
873
|
-
getValidator(): Promise<{ validator: Record<string, unknown> | null; validationLevel: string; validationAction: string }>;
|
|
874
|
-
/** Returns collection storage and index statistics. @since v1.3.0 */
|
|
875
|
-
stats(options?: { scale?: number }): Promise<{ ns: string; count: number; size: number; storageSize: number; totalIndexSize: number; nindexes: number; avgObjSize?: number; scaleFactor?: number }>;
|
|
876
|
-
/** Renames the collection, optionally dropping an existing target. @since v1.3.0 */
|
|
877
|
-
renameCollection(newName: string, options?: { dropTarget?: boolean }): Promise<{ renamed: boolean; from: string; to: string }>;
|
|
878
|
-
/** Runs a `collMod` command against the collection. @since v1.3.0 */
|
|
879
|
-
collMod(modifications: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
880
|
-
/** Converts the collection to capped storage. @since v1.3.0 */
|
|
881
|
-
convertToCapped(size: number, options?: { max?: number }): Promise<{ ok: number; collection: string; capped: boolean; size: number }>;
|
|
882
|
-
}
|
|
883
|
-
|
|
820
|
+
/**
|
|
821
|
+
* Opens a MongoDB change stream to listen for collection-level change events.
|
|
822
|
+
* @param pipeline - Optional aggregation pipeline to filter/transform events.
|
|
823
|
+
* @param options - MongoDB ChangeStreamOptions.
|
|
824
|
+
* @returns A ChangeStream instance emitting change event documents.
|
|
825
|
+
*/
|
|
826
|
+
watch(pipeline?: unknown[], options?: unknown): ChangeStream;
|
|
827
|
+
/**
|
|
828
|
+
* Manually invalidates cached query results for the specified operation type.
|
|
829
|
+
* @param op - Operation whose cache entries to clear; omit to clear all.
|
|
830
|
+
* @returns Number of cache entries removed.
|
|
831
|
+
* @since v1.3.0
|
|
832
|
+
*/
|
|
833
|
+
invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise<number>;
|
|
834
|
+
/**
|
|
835
|
+
* Drops the entire collection from the database.
|
|
836
|
+
* @returns True when the collection was dropped successfully.
|
|
837
|
+
* @since v1.3.0
|
|
838
|
+
*/
|
|
839
|
+
dropCollection(): Promise<boolean>;
|
|
840
|
+
/**
|
|
841
|
+
* Creates a new collection (or capped collection) in the database.
|
|
842
|
+
* @param name - Collection name; defaults to the current collection name when omitted.
|
|
843
|
+
* @param options - MongoDB CreateCollectionOptions (capped, size, validator, …).
|
|
844
|
+
* @returns True when the collection was created successfully.
|
|
845
|
+
* @since v1.3.0
|
|
846
|
+
*/
|
|
847
|
+
createCollection(name?: string, options?: Record<string, unknown>): Promise<boolean>;
|
|
848
|
+
/**
|
|
849
|
+
* Creates a MongoDB view backed by an aggregation pipeline over a source collection.
|
|
850
|
+
* @param name - Name of the view to create.
|
|
851
|
+
* @param source - Name of the source collection.
|
|
852
|
+
* @param pipeline - Optional aggregation pipeline defining the view.
|
|
853
|
+
* @returns True when the view was created successfully.
|
|
854
|
+
* @since v1.3.0
|
|
855
|
+
*/
|
|
856
|
+
createView(name: string, source: string, pipeline?: unknown[]): Promise<boolean>;
|
|
857
|
+
/**
|
|
858
|
+
* Returns index usage statistics for all indexes on the collection.
|
|
859
|
+
* @returns Array of `$indexStats` documents from MongoDB.
|
|
860
|
+
* @since v1.3.0
|
|
861
|
+
*/
|
|
862
|
+
indexStats(): Promise<unknown[]>;
|
|
863
|
+
/**
|
|
864
|
+
* Sets the JSON Schema validator and optional validation settings.
|
|
865
|
+
* @since v1.3.0
|
|
866
|
+
*/
|
|
867
|
+
setValidator(validator: unknown, options?: { validationLevel?: string; validationAction?: string }): Promise<{ ok: number; collection: string }>;
|
|
868
|
+
/** Sets the collection validation level. @since v1.3.0 */
|
|
869
|
+
setValidationLevel(level: 'off' | 'moderate' | 'strict' | string): Promise<{ ok: number; validationLevel: string }>;
|
|
870
|
+
/** Sets the collection validation action. @since v1.3.0 */
|
|
871
|
+
setValidationAction(action: 'error' | 'warn' | string): Promise<{ ok: number; validationAction: string }>;
|
|
872
|
+
/** Reads the current collection validator and validation settings. @since v1.3.0 */
|
|
873
|
+
getValidator(): Promise<{ validator: Record<string, unknown> | null; validationLevel: string; validationAction: string }>;
|
|
874
|
+
/** Returns collection storage and index statistics. @since v1.3.0 */
|
|
875
|
+
stats(options?: { scale?: number }): Promise<{ ns: string; count: number; size: number; storageSize: number; totalIndexSize: number; nindexes: number; avgObjSize?: number; scaleFactor?: number }>;
|
|
876
|
+
/** Renames the collection, optionally dropping an existing target. @since v1.3.0 */
|
|
877
|
+
renameCollection(newName: string, options?: { dropTarget?: boolean }): Promise<{ renamed: boolean; from: string; to: string }>;
|
|
878
|
+
/** Runs a `collMod` command against the collection. @since v1.3.0 */
|
|
879
|
+
collMod(modifications: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
880
|
+
/** Converts the collection to capped storage. @since v1.3.0 */
|
|
881
|
+
convertToCapped(size: number, options?: { max?: number }): Promise<{ ok: number; collection: string; capped: boolean; size: number }>;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
884
|
export interface DbAccessor {
|
|
885
|
-
/**
|
|
886
|
-
* Returns a typed Collection accessor for the named collection.
|
|
887
|
-
* @param name - MongoDB collection name.
|
|
888
|
-
* @returns Collection instance bound to the specified collection.
|
|
889
|
-
*/
|
|
885
|
+
/**
|
|
886
|
+
* Returns a typed Collection accessor for the named collection.
|
|
887
|
+
* @param name - MongoDB collection name.
|
|
888
|
+
* @returns Collection instance bound to the specified collection.
|
|
889
|
+
*/
|
|
890
890
|
collection<TSchema = any>(name: string): Collection<TSchema>;
|
|
891
|
-
/** Returns the underlying native MongoDB Db object. */
|
|
892
|
-
raw(): unknown;
|
|
893
|
-
/** Returns an AdminAccessor for server-level administrative operations. */
|
|
894
|
-
admin(): AdminAccessor;
|
|
895
|
-
/**
|
|
896
|
-
* Lists all databases available on the server.
|
|
897
|
-
* @param options - Pass `nameOnly: true` to return string names instead of full descriptors.
|
|
898
|
-
* @returns Array of database descriptor objects, or string names when `nameOnly` is true.
|
|
899
|
-
* @since v1.3.0
|
|
900
|
-
*/
|
|
901
|
-
listDatabases(options?: { nameOnly?: boolean }): Promise<Array<{ name: string; sizeOnDisk: number; empty: boolean }> | string[]>;
|
|
902
|
-
/**
|
|
903
|
-
* Drops the current database; requires explicit confirmation to prevent accidental data loss.
|
|
904
|
-
* @param options - Must include `confirm: true`; optionally restrict to non-production environments.
|
|
905
|
-
* @returns Result object with the dropped database name and timestamp.
|
|
906
|
-
* @since v1.3.0
|
|
907
|
-
*/
|
|
908
|
-
dropDatabase(options?: { confirm: boolean; allowProduction?: boolean; user?: string }): Promise<{ dropped: boolean; database: string; timestamp: Date }>;
|
|
909
|
-
/**
|
|
910
|
-
* Lists collections (and views) in the current database.
|
|
911
|
-
* @param filter - Optional MongoDB filter applied to the collection list.
|
|
912
|
-
* @param options - MongoDB ListCollectionsOptions.
|
|
913
|
-
* @returns Array of objects with `name` and `type` fields.
|
|
914
|
-
* @since v1.3.0
|
|
915
|
-
*/
|
|
916
|
-
listCollections(filter?: Record<string, unknown>, options?: Record<string, unknown>): Promise<Array<{ name: string; type: string }>>;
|
|
917
|
-
/**
|
|
918
|
-
* Runs an arbitrary command against the current database.
|
|
919
|
-
* @param command - Command document (e.g. `{ ping: 1 }`).
|
|
920
|
-
* @param options - MongoDB RunCommandOptions.
|
|
921
|
-
* @returns Raw command result document from MongoDB.
|
|
922
|
-
* @since v1.3.0
|
|
923
|
-
*/
|
|
924
|
-
runCommand(command: Record<string, unknown>, options?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
// ---------------------------------------------------------------------------
|
|
928
|
-
// v1 backward-compat name aliases
|
|
929
|
-
// ---------------------------------------------------------------------------
|
|
930
|
-
|
|
931
|
-
/** @alias FindPageResult — v1 called the findPage result PageResult */
|
|
891
|
+
/** Returns the underlying native MongoDB Db object. */
|
|
892
|
+
raw(): unknown;
|
|
893
|
+
/** Returns an AdminAccessor for server-level administrative operations. */
|
|
894
|
+
admin(): AdminAccessor;
|
|
895
|
+
/**
|
|
896
|
+
* Lists all databases available on the server.
|
|
897
|
+
* @param options - Pass `nameOnly: true` to return string names instead of full descriptors.
|
|
898
|
+
* @returns Array of database descriptor objects, or string names when `nameOnly` is true.
|
|
899
|
+
* @since v1.3.0
|
|
900
|
+
*/
|
|
901
|
+
listDatabases(options?: { nameOnly?: boolean }): Promise<Array<{ name: string; sizeOnDisk: number; empty: boolean }> | string[]>;
|
|
902
|
+
/**
|
|
903
|
+
* Drops the current database; requires explicit confirmation to prevent accidental data loss.
|
|
904
|
+
* @param options - Must include `confirm: true`; optionally restrict to non-production environments.
|
|
905
|
+
* @returns Result object with the dropped database name and timestamp.
|
|
906
|
+
* @since v1.3.0
|
|
907
|
+
*/
|
|
908
|
+
dropDatabase(options?: { confirm: boolean; allowProduction?: boolean; user?: string }): Promise<{ dropped: boolean; database: string; timestamp: Date }>;
|
|
909
|
+
/**
|
|
910
|
+
* Lists collections (and views) in the current database.
|
|
911
|
+
* @param filter - Optional MongoDB filter applied to the collection list.
|
|
912
|
+
* @param options - MongoDB ListCollectionsOptions.
|
|
913
|
+
* @returns Array of objects with `name` and `type` fields.
|
|
914
|
+
* @since v1.3.0
|
|
915
|
+
*/
|
|
916
|
+
listCollections(filter?: Record<string, unknown>, options?: Record<string, unknown>): Promise<Array<{ name: string; type: string }>>;
|
|
917
|
+
/**
|
|
918
|
+
* Runs an arbitrary command against the current database.
|
|
919
|
+
* @param command - Command document (e.g. `{ ping: 1 }`).
|
|
920
|
+
* @param options - MongoDB RunCommandOptions.
|
|
921
|
+
* @returns Raw command result document from MongoDB.
|
|
922
|
+
* @since v1.3.0
|
|
923
|
+
*/
|
|
924
|
+
runCommand(command: Record<string, unknown>, options?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// ---------------------------------------------------------------------------
|
|
928
|
+
// v1 backward-compat name aliases
|
|
929
|
+
// ---------------------------------------------------------------------------
|
|
930
|
+
|
|
931
|
+
/** @alias FindPageResult — v1 called the findPage result PageResult */
|
|
932
932
|
export type PageResult<T = any> = FindPageResult<T>;
|
|
933
|
-
|
|
934
|
-
/** @alias BookmarkPrewarmResult — v1 name */
|
|
935
|
-
export type PrewarmBookmarksResult = BookmarkPrewarmResult;
|
|
936
|
-
|
|
937
|
-
/** @alias BookmarkListResult — v1 name */
|
|
938
|
-
export type ListBookmarksResult = BookmarkListResult;
|
|
939
|
-
|
|
940
|
-
/** @alias BookmarkClearResult — v1 name */
|
|
941
|
-
export type ClearBookmarksResult = BookmarkClearResult;
|
|
942
|
-
|
|
943
|
-
// ---------------------------------------------------------------------------
|
|
944
|
-
// Write options (v1 parity)
|
|
945
|
-
// ---------------------------------------------------------------------------
|
|
946
|
-
|
|
947
|
-
/** Simplified insertOne options (used for the shorthand call form). */
|
|
948
|
-
export interface InsertOneSimplifiedOptions {
|
|
949
|
-
writeConcern?: WriteConcern;
|
|
950
|
-
bypassDocumentValidation?: boolean;
|
|
951
|
-
comment?: string;
|
|
952
|
-
session?: unknown;
|
|
953
|
-
/** Invalidate query cache on success. @since v1.1.5 */
|
|
954
|
-
autoInvalidate?: boolean;
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
/** Full insertOne options (document + write configuration). */
|
|
958
|
-
export interface InsertOneOptions {
|
|
959
|
-
document: unknown;
|
|
960
|
-
writeConcern?: WriteConcern;
|
|
961
|
-
bypassDocumentValidation?: boolean;
|
|
962
|
-
comment?: string;
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
/** Simplified insertMany options (used for the shorthand call form). */
|
|
966
|
-
export interface InsertManySimplifiedOptions {
|
|
967
|
-
ordered?: boolean;
|
|
968
|
-
writeConcern?: WriteConcern;
|
|
969
|
-
bypassDocumentValidation?: boolean;
|
|
970
|
-
comment?: string;
|
|
971
|
-
session?: unknown;
|
|
972
|
-
/** Invalidate query cache on success. @since v1.1.5 */
|
|
973
|
-
autoInvalidate?: boolean;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
/** Full insertMany options (documents array + write configuration). */
|
|
977
|
-
export interface InsertManyOptions {
|
|
978
|
-
documents: unknown[];
|
|
979
|
-
ordered?: boolean;
|
|
980
|
-
writeConcern?: WriteConcern;
|
|
981
|
-
bypassDocumentValidation?: boolean;
|
|
982
|
-
comment?: string;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
// ---------------------------------------------------------------------------
|
|
986
|
-
// Chain helpers (v1 parity)
|
|
987
|
-
// ---------------------------------------------------------------------------
|
|
988
|
-
|
|
989
|
-
/**
|
|
990
|
-
* Collation options for locale-aware string comparison.
|
|
991
|
-
* @since v1.0.0
|
|
992
|
-
*/
|
|
993
|
-
export interface CollationOptions {
|
|
994
|
-
/** IETF language tag, e.g. 'en', 'zh'. */
|
|
995
|
-
locale: string;
|
|
996
|
-
/** Comparison strength: 1=base, 2=accent, 3=case. */
|
|
997
|
-
strength?: number;
|
|
998
|
-
/** Distinguish uppercase from lowercase at strength < 3. */
|
|
999
|
-
caseLevel?: boolean;
|
|
1000
|
-
/** Which case is sorted first when cases are equal. */
|
|
1001
|
-
caseFirst?: 'upper' | 'lower';
|
|
1002
|
-
/** Sort numeric strings numerically, not lexicographically. */
|
|
1003
|
-
numericOrdering?: boolean;
|
|
1004
|
-
/** How spaces and punctuation are handled. */
|
|
1005
|
-
alternate?: 'non-ignorable' | 'shifted';
|
|
1006
|
-
/** Highest ignored character category. */
|
|
1007
|
-
maxVariable?: 'punct' | 'space';
|
|
1008
|
-
/** Sort secondary weights in reverse order. */
|
|
1009
|
-
backwards?: boolean;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
// ---------------------------------------------------------------------------
|
|
1013
|
-
// Pagination helpers (v1 parity)
|
|
1014
|
-
// ---------------------------------------------------------------------------
|
|
1015
|
-
|
|
1016
|
-
/**
|
|
1017
|
-
* Query result with attached metadata (timing, cache, totals).
|
|
1018
|
-
* @since v1.3.0
|
|
1019
|
-
*/
|
|
1020
|
-
export interface ResultWithMeta<T = unknown> {
|
|
1021
|
-
data: T;
|
|
1022
|
-
meta: MetaInfo;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
// ---------------------------------------------------------------------------
|
|
1026
|
-
// Collection accessor alias (v1 parity)
|
|
1027
|
-
// ---------------------------------------------------------------------------
|
|
1028
|
-
|
|
1029
|
-
/** @alias Collection — v1 called the collection accessor CollectionAccessor */
|
|
933
|
+
|
|
934
|
+
/** @alias BookmarkPrewarmResult — v1 name */
|
|
935
|
+
export type PrewarmBookmarksResult = BookmarkPrewarmResult;
|
|
936
|
+
|
|
937
|
+
/** @alias BookmarkListResult — v1 name */
|
|
938
|
+
export type ListBookmarksResult = BookmarkListResult;
|
|
939
|
+
|
|
940
|
+
/** @alias BookmarkClearResult — v1 name */
|
|
941
|
+
export type ClearBookmarksResult = BookmarkClearResult;
|
|
942
|
+
|
|
943
|
+
// ---------------------------------------------------------------------------
|
|
944
|
+
// Write options (v1 parity)
|
|
945
|
+
// ---------------------------------------------------------------------------
|
|
946
|
+
|
|
947
|
+
/** Simplified insertOne options (used for the shorthand call form). */
|
|
948
|
+
export interface InsertOneSimplifiedOptions {
|
|
949
|
+
writeConcern?: WriteConcern;
|
|
950
|
+
bypassDocumentValidation?: boolean;
|
|
951
|
+
comment?: string;
|
|
952
|
+
session?: unknown;
|
|
953
|
+
/** Invalidate query cache on success. @since v1.1.5 */
|
|
954
|
+
autoInvalidate?: boolean;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/** Full insertOne options (document + write configuration). */
|
|
958
|
+
export interface InsertOneOptions {
|
|
959
|
+
document: unknown;
|
|
960
|
+
writeConcern?: WriteConcern;
|
|
961
|
+
bypassDocumentValidation?: boolean;
|
|
962
|
+
comment?: string;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/** Simplified insertMany options (used for the shorthand call form). */
|
|
966
|
+
export interface InsertManySimplifiedOptions {
|
|
967
|
+
ordered?: boolean;
|
|
968
|
+
writeConcern?: WriteConcern;
|
|
969
|
+
bypassDocumentValidation?: boolean;
|
|
970
|
+
comment?: string;
|
|
971
|
+
session?: unknown;
|
|
972
|
+
/** Invalidate query cache on success. @since v1.1.5 */
|
|
973
|
+
autoInvalidate?: boolean;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/** Full insertMany options (documents array + write configuration). */
|
|
977
|
+
export interface InsertManyOptions {
|
|
978
|
+
documents: unknown[];
|
|
979
|
+
ordered?: boolean;
|
|
980
|
+
writeConcern?: WriteConcern;
|
|
981
|
+
bypassDocumentValidation?: boolean;
|
|
982
|
+
comment?: string;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// ---------------------------------------------------------------------------
|
|
986
|
+
// Chain helpers (v1 parity)
|
|
987
|
+
// ---------------------------------------------------------------------------
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* Collation options for locale-aware string comparison.
|
|
991
|
+
* @since v1.0.0
|
|
992
|
+
*/
|
|
993
|
+
export interface CollationOptions {
|
|
994
|
+
/** IETF language tag, e.g. 'en', 'zh'. */
|
|
995
|
+
locale: string;
|
|
996
|
+
/** Comparison strength: 1=base, 2=accent, 3=case. */
|
|
997
|
+
strength?: number;
|
|
998
|
+
/** Distinguish uppercase from lowercase at strength < 3. */
|
|
999
|
+
caseLevel?: boolean;
|
|
1000
|
+
/** Which case is sorted first when cases are equal. */
|
|
1001
|
+
caseFirst?: 'upper' | 'lower';
|
|
1002
|
+
/** Sort numeric strings numerically, not lexicographically. */
|
|
1003
|
+
numericOrdering?: boolean;
|
|
1004
|
+
/** How spaces and punctuation are handled. */
|
|
1005
|
+
alternate?: 'non-ignorable' | 'shifted';
|
|
1006
|
+
/** Highest ignored character category. */
|
|
1007
|
+
maxVariable?: 'punct' | 'space';
|
|
1008
|
+
/** Sort secondary weights in reverse order. */
|
|
1009
|
+
backwards?: boolean;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// ---------------------------------------------------------------------------
|
|
1013
|
+
// Pagination helpers (v1 parity)
|
|
1014
|
+
// ---------------------------------------------------------------------------
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Query result with attached metadata (timing, cache, totals).
|
|
1018
|
+
* @since v1.3.0
|
|
1019
|
+
*/
|
|
1020
|
+
export interface ResultWithMeta<T = unknown> {
|
|
1021
|
+
data: T;
|
|
1022
|
+
meta: MetaInfo;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
// ---------------------------------------------------------------------------
|
|
1026
|
+
// Collection accessor alias (v1 parity)
|
|
1027
|
+
// ---------------------------------------------------------------------------
|
|
1028
|
+
|
|
1029
|
+
/** @alias Collection — v1 called the collection accessor CollectionAccessor */
|
|
1030
1030
|
export type CollectionAccessor<TSchema = any> = Collection<TSchema>;
|
|
1031
|
-
|
|
1031
|
+
|