mongodb 6.7.0-dev.20240607.sha.aa429f8c → 6.7.0-dev.20240608.sha.0655c730
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/lib/cursor/abstract_cursor.js +234 -268
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +10 -17
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/change_stream_cursor.js +6 -6
- package/lib/cursor/change_stream_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +64 -72
- package/lib/cursor/find_cursor.js.map +1 -1
- package/mongodb.d.ts +23 -53
- package/package.json +1 -1
- package/src/cursor/abstract_cursor.ts +259 -348
- package/src/cursor/aggregation_cursor.ts +13 -23
- package/src/cursor/change_stream_cursor.ts +12 -15
- package/src/cursor/find_cursor.ts +67 -74
|
@@ -8,16 +8,11 @@ import type { Sort } from '../sort';
|
|
|
8
8
|
import type { MongoDBNamespace } from '../utils';
|
|
9
9
|
import { mergeOptions } from '../utils';
|
|
10
10
|
import type { AbstractCursorOptions } from './abstract_cursor';
|
|
11
|
-
import { AbstractCursor
|
|
11
|
+
import { AbstractCursor } from './abstract_cursor';
|
|
12
12
|
|
|
13
13
|
/** @public */
|
|
14
14
|
export interface AggregationCursorOptions extends AbstractCursorOptions, AggregateOptions {}
|
|
15
15
|
|
|
16
|
-
/** @internal */
|
|
17
|
-
const kPipeline = Symbol('pipeline');
|
|
18
|
-
/** @internal */
|
|
19
|
-
const kOptions = Symbol('options');
|
|
20
|
-
|
|
21
16
|
/**
|
|
22
17
|
* The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
|
|
23
18
|
* allowing for iteration over the results returned from the underlying query. It supports
|
|
@@ -26,10 +21,9 @@ const kOptions = Symbol('options');
|
|
|
26
21
|
* @public
|
|
27
22
|
*/
|
|
28
23
|
export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
24
|
+
public readonly pipeline: Document[];
|
|
29
25
|
/** @internal */
|
|
30
|
-
|
|
31
|
-
/** @internal */
|
|
32
|
-
[kOptions]: AggregateOptions;
|
|
26
|
+
private aggregateOptions: AggregateOptions;
|
|
33
27
|
|
|
34
28
|
/** @internal */
|
|
35
29
|
constructor(
|
|
@@ -40,18 +34,14 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
40
34
|
) {
|
|
41
35
|
super(client, namespace, options);
|
|
42
36
|
|
|
43
|
-
this
|
|
44
|
-
this
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get pipeline(): Document[] {
|
|
48
|
-
return this[kPipeline];
|
|
37
|
+
this.pipeline = pipeline;
|
|
38
|
+
this.aggregateOptions = options;
|
|
49
39
|
}
|
|
50
40
|
|
|
51
41
|
clone(): AggregationCursor<TSchema> {
|
|
52
|
-
const clonedOptions = mergeOptions({}, this
|
|
42
|
+
const clonedOptions = mergeOptions({}, this.aggregateOptions);
|
|
53
43
|
delete clonedOptions.session;
|
|
54
|
-
return new AggregationCursor(this.client, this.namespace, this
|
|
44
|
+
return new AggregationCursor(this.client, this.namespace, this.pipeline, {
|
|
55
45
|
...clonedOptions
|
|
56
46
|
});
|
|
57
47
|
}
|
|
@@ -62,8 +52,8 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
62
52
|
|
|
63
53
|
/** @internal */
|
|
64
54
|
async _initialize(session: ClientSession): Promise<ExecutionResult> {
|
|
65
|
-
const aggregateOperation = new AggregateOperation(this.namespace, this
|
|
66
|
-
...this
|
|
55
|
+
const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, {
|
|
56
|
+
...this.aggregateOptions,
|
|
67
57
|
...this.cursorOptions,
|
|
68
58
|
session
|
|
69
59
|
});
|
|
@@ -78,8 +68,8 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
78
68
|
async explain(verbosity?: ExplainVerbosityLike): Promise<Document> {
|
|
79
69
|
return await executeOperation(
|
|
80
70
|
this.client,
|
|
81
|
-
new AggregateOperation(this.namespace, this
|
|
82
|
-
...this
|
|
71
|
+
new AggregateOperation(this.namespace, this.pipeline, {
|
|
72
|
+
...this.aggregateOptions, // NOTE: order matters here, we may need to refine this
|
|
83
73
|
...this.cursorOptions,
|
|
84
74
|
explain: verbosity ?? true
|
|
85
75
|
})
|
|
@@ -101,8 +91,8 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
101
91
|
addStage(stage: Document): this;
|
|
102
92
|
addStage<T = Document>(stage: Document): AggregationCursor<T>;
|
|
103
93
|
addStage<T = Document>(stage: Document): AggregationCursor<T> {
|
|
104
|
-
|
|
105
|
-
this
|
|
94
|
+
this.throwIfInitialized();
|
|
95
|
+
this.pipeline.push(stage);
|
|
106
96
|
return this as unknown as AggregationCursor<T>;
|
|
107
97
|
}
|
|
108
98
|
|
|
@@ -43,15 +43,12 @@ export class ChangeStreamCursor<
|
|
|
43
43
|
TSchema extends Document = Document,
|
|
44
44
|
TChange extends Document = ChangeStreamDocument<TSchema>
|
|
45
45
|
> extends AbstractCursor<TChange, ChangeStreamEvents> {
|
|
46
|
-
_resumeToken: ResumeToken;
|
|
47
|
-
startAtOperationTime?: OperationTime;
|
|
48
|
-
hasReceived?: boolean;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
postBatchResumeToken?: ResumeToken;
|
|
54
|
-
pipeline: Document[];
|
|
46
|
+
private _resumeToken: ResumeToken;
|
|
47
|
+
private startAtOperationTime?: OperationTime;
|
|
48
|
+
private hasReceived?: boolean;
|
|
49
|
+
private readonly changeStreamCursorOptions: ChangeStreamCursorOptions;
|
|
50
|
+
private postBatchResumeToken?: ResumeToken;
|
|
51
|
+
private readonly pipeline: Document[];
|
|
55
52
|
|
|
56
53
|
/**
|
|
57
54
|
* @internal
|
|
@@ -69,7 +66,7 @@ export class ChangeStreamCursor<
|
|
|
69
66
|
super(client, namespace, options);
|
|
70
67
|
|
|
71
68
|
this.pipeline = pipeline;
|
|
72
|
-
this.
|
|
69
|
+
this.changeStreamCursorOptions = options;
|
|
73
70
|
this._resumeToken = null;
|
|
74
71
|
this.startAtOperationTime = options.startAtOperationTime;
|
|
75
72
|
|
|
@@ -91,7 +88,7 @@ export class ChangeStreamCursor<
|
|
|
91
88
|
|
|
92
89
|
get resumeOptions(): ChangeStreamCursorOptions {
|
|
93
90
|
const options: ChangeStreamCursorOptions = {
|
|
94
|
-
...this.
|
|
91
|
+
...this.changeStreamCursorOptions
|
|
95
92
|
};
|
|
96
93
|
|
|
97
94
|
for (const key of ['resumeAfter', 'startAfter', 'startAtOperationTime'] as const) {
|
|
@@ -99,7 +96,7 @@ export class ChangeStreamCursor<
|
|
|
99
96
|
}
|
|
100
97
|
|
|
101
98
|
if (this.resumeToken != null) {
|
|
102
|
-
if (this.
|
|
99
|
+
if (this.changeStreamCursorOptions.startAfter && !this.hasReceived) {
|
|
103
100
|
options.startAfter = this.resumeToken;
|
|
104
101
|
} else {
|
|
105
102
|
options.resumeAfter = this.resumeToken;
|
|
@@ -142,7 +139,7 @@ export class ChangeStreamCursor<
|
|
|
142
139
|
async _initialize(session: ClientSession): Promise<ExecutionResult> {
|
|
143
140
|
const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, {
|
|
144
141
|
...this.cursorOptions,
|
|
145
|
-
...this.
|
|
142
|
+
...this.changeStreamCursorOptions,
|
|
146
143
|
session
|
|
147
144
|
});
|
|
148
145
|
|
|
@@ -156,8 +153,8 @@ export class ChangeStreamCursor<
|
|
|
156
153
|
|
|
157
154
|
if (
|
|
158
155
|
this.startAtOperationTime == null &&
|
|
159
|
-
this.resumeAfter == null &&
|
|
160
|
-
this.startAfter == null &&
|
|
156
|
+
this.changeStreamCursorOptions.resumeAfter == null &&
|
|
157
|
+
this.changeStreamCursorOptions.startAfter == null &&
|
|
161
158
|
this.maxWireVersion >= 7
|
|
162
159
|
) {
|
|
163
160
|
this.startAtOperationTime = response.operationTime;
|
|
@@ -11,14 +11,7 @@ import type { Hint } from '../operations/operation';
|
|
|
11
11
|
import type { ClientSession } from '../sessions';
|
|
12
12
|
import { formatSort, type Sort, type SortDirection } from '../sort';
|
|
13
13
|
import { emitWarningOnce, mergeOptions, type MongoDBNamespace, squashError } from '../utils';
|
|
14
|
-
import { AbstractCursor
|
|
15
|
-
|
|
16
|
-
/** @internal */
|
|
17
|
-
const kFilter = Symbol('filter');
|
|
18
|
-
/** @internal */
|
|
19
|
-
const kNumReturned = Symbol('numReturned');
|
|
20
|
-
/** @internal */
|
|
21
|
-
const kBuiltOptions = Symbol('builtOptions');
|
|
14
|
+
import { AbstractCursor } from './abstract_cursor';
|
|
22
15
|
|
|
23
16
|
/** @public Flags allowed for cursor */
|
|
24
17
|
export const FLAGS = [
|
|
@@ -33,11 +26,11 @@ export const FLAGS = [
|
|
|
33
26
|
/** @public */
|
|
34
27
|
export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
35
28
|
/** @internal */
|
|
36
|
-
|
|
29
|
+
private cursorFilter: Document;
|
|
37
30
|
/** @internal */
|
|
38
|
-
|
|
31
|
+
private numReturned = 0;
|
|
39
32
|
/** @internal */
|
|
40
|
-
|
|
33
|
+
private readonly findOptions: FindOptions;
|
|
41
34
|
|
|
42
35
|
/** @internal */
|
|
43
36
|
constructor(
|
|
@@ -48,18 +41,18 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
48
41
|
) {
|
|
49
42
|
super(client, namespace, options);
|
|
50
43
|
|
|
51
|
-
this
|
|
52
|
-
this
|
|
44
|
+
this.cursorFilter = filter;
|
|
45
|
+
this.findOptions = options;
|
|
53
46
|
|
|
54
47
|
if (options.sort != null) {
|
|
55
|
-
this
|
|
48
|
+
this.findOptions.sort = formatSort(options.sort);
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
clone(): FindCursor<TSchema> {
|
|
60
|
-
const clonedOptions = mergeOptions({}, this
|
|
53
|
+
const clonedOptions = mergeOptions({}, this.findOptions);
|
|
61
54
|
delete clonedOptions.session;
|
|
62
|
-
return new FindCursor(this.client, this.namespace, this
|
|
55
|
+
return new FindCursor(this.client, this.namespace, this.cursorFilter, {
|
|
63
56
|
...clonedOptions
|
|
64
57
|
});
|
|
65
58
|
}
|
|
@@ -70,8 +63,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
70
63
|
|
|
71
64
|
/** @internal */
|
|
72
65
|
async _initialize(session: ClientSession): Promise<ExecutionResult> {
|
|
73
|
-
const findOperation = new FindOperation(this.namespace, this
|
|
74
|
-
...this
|
|
66
|
+
const findOperation = new FindOperation(this.namespace, this.cursorFilter, {
|
|
67
|
+
...this.findOptions, // NOTE: order matters here, we may need to refine this
|
|
75
68
|
...this.cursorOptions,
|
|
76
69
|
session
|
|
77
70
|
});
|
|
@@ -80,10 +73,10 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
80
73
|
|
|
81
74
|
// the response is not a cursor when `explain` is enabled
|
|
82
75
|
if (CursorResponse.is(response)) {
|
|
83
|
-
this
|
|
76
|
+
this.numReturned = response.batchSize;
|
|
84
77
|
} else {
|
|
85
78
|
// Can be an explain response, hence the ?. on everything
|
|
86
|
-
this
|
|
79
|
+
this.numReturned = this.numReturned + (response?.cursor?.firstBatch?.length ?? 0);
|
|
87
80
|
}
|
|
88
81
|
|
|
89
82
|
// TODO: NODE-2882
|
|
@@ -92,10 +85,10 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
92
85
|
|
|
93
86
|
/** @internal */
|
|
94
87
|
override async getMore(batchSize: number): Promise<Document | null> {
|
|
95
|
-
const numReturned = this
|
|
88
|
+
const numReturned = this.numReturned;
|
|
96
89
|
if (numReturned) {
|
|
97
90
|
// TODO(DRIVERS-1448): Remove logic to enforce `limit` in the driver
|
|
98
|
-
const limit = this
|
|
91
|
+
const limit = this.findOptions.limit;
|
|
99
92
|
batchSize =
|
|
100
93
|
limit && limit > 0 && numReturned + batchSize > limit ? limit - numReturned : batchSize;
|
|
101
94
|
|
|
@@ -120,9 +113,9 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
120
113
|
const response = await super.getMore(batchSize, false);
|
|
121
114
|
// TODO: wrap this in some logic to prevent it from happening if we don't need this support
|
|
122
115
|
if (CursorResponse.is(response)) {
|
|
123
|
-
this
|
|
116
|
+
this.numReturned = this.numReturned + response.batchSize;
|
|
124
117
|
} else {
|
|
125
|
-
this
|
|
118
|
+
this.numReturned = this.numReturned + (response?.cursor?.nextBatch?.length ?? 0);
|
|
126
119
|
}
|
|
127
120
|
|
|
128
121
|
return response;
|
|
@@ -141,8 +134,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
141
134
|
}
|
|
142
135
|
return await executeOperation(
|
|
143
136
|
this.client,
|
|
144
|
-
new CountOperation(this.namespace, this
|
|
145
|
-
...this
|
|
137
|
+
new CountOperation(this.namespace, this.cursorFilter, {
|
|
138
|
+
...this.findOptions, // NOTE: order matters here, we may need to refine this
|
|
146
139
|
...this.cursorOptions,
|
|
147
140
|
...options
|
|
148
141
|
})
|
|
@@ -153,8 +146,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
153
146
|
async explain(verbosity?: ExplainVerbosityLike): Promise<Document> {
|
|
154
147
|
return await executeOperation(
|
|
155
148
|
this.client,
|
|
156
|
-
new FindOperation(this.namespace, this
|
|
157
|
-
...this
|
|
149
|
+
new FindOperation(this.namespace, this.cursorFilter, {
|
|
150
|
+
...this.findOptions, // NOTE: order matters here, we may need to refine this
|
|
158
151
|
...this.cursorOptions,
|
|
159
152
|
explain: verbosity ?? true
|
|
160
153
|
})
|
|
@@ -163,8 +156,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
163
156
|
|
|
164
157
|
/** Set the cursor query */
|
|
165
158
|
filter(filter: Document): this {
|
|
166
|
-
|
|
167
|
-
this
|
|
159
|
+
this.throwIfInitialized();
|
|
160
|
+
this.cursorFilter = filter;
|
|
168
161
|
return this;
|
|
169
162
|
}
|
|
170
163
|
|
|
@@ -174,8 +167,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
174
167
|
* @param hint - If specified, then the query system will only consider plans using the hinted index.
|
|
175
168
|
*/
|
|
176
169
|
hint(hint: Hint): this {
|
|
177
|
-
|
|
178
|
-
this
|
|
170
|
+
this.throwIfInitialized();
|
|
171
|
+
this.findOptions.hint = hint;
|
|
179
172
|
return this;
|
|
180
173
|
}
|
|
181
174
|
|
|
@@ -185,8 +178,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
185
178
|
* @param min - Specify a $min value to specify the inclusive lower bound for a specific index in order to constrain the results of find(). The $min specifies the lower bound for all keys of a specific index in order.
|
|
186
179
|
*/
|
|
187
180
|
min(min: Document): this {
|
|
188
|
-
|
|
189
|
-
this
|
|
181
|
+
this.throwIfInitialized();
|
|
182
|
+
this.findOptions.min = min;
|
|
190
183
|
return this;
|
|
191
184
|
}
|
|
192
185
|
|
|
@@ -196,8 +189,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
196
189
|
* @param max - Specify a $max value to specify the exclusive upper bound for a specific index in order to constrain the results of find(). The $max specifies the upper bound for all keys of a specific index in order.
|
|
197
190
|
*/
|
|
198
191
|
max(max: Document): this {
|
|
199
|
-
|
|
200
|
-
this
|
|
192
|
+
this.throwIfInitialized();
|
|
193
|
+
this.findOptions.max = max;
|
|
201
194
|
return this;
|
|
202
195
|
}
|
|
203
196
|
|
|
@@ -209,8 +202,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
209
202
|
* @param value - the returnKey value.
|
|
210
203
|
*/
|
|
211
204
|
returnKey(value: boolean): this {
|
|
212
|
-
|
|
213
|
-
this
|
|
205
|
+
this.throwIfInitialized();
|
|
206
|
+
this.findOptions.returnKey = value;
|
|
214
207
|
return this;
|
|
215
208
|
}
|
|
216
209
|
|
|
@@ -220,8 +213,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
220
213
|
* @param value - The $showDiskLoc option has now been deprecated and replaced with the showRecordId field. $showDiskLoc will still be accepted for OP_QUERY stye find.
|
|
221
214
|
*/
|
|
222
215
|
showRecordId(value: boolean): this {
|
|
223
|
-
|
|
224
|
-
this
|
|
216
|
+
this.throwIfInitialized();
|
|
217
|
+
this.findOptions.showRecordId = value;
|
|
225
218
|
return this;
|
|
226
219
|
}
|
|
227
220
|
|
|
@@ -232,7 +225,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
232
225
|
* @param value - The modifier value.
|
|
233
226
|
*/
|
|
234
227
|
addQueryModifier(name: string, value: string | boolean | number | Document): this {
|
|
235
|
-
|
|
228
|
+
this.throwIfInitialized();
|
|
236
229
|
if (name[0] !== '$') {
|
|
237
230
|
throw new MongoInvalidArgumentError(`${name} is not a valid query modifier`);
|
|
238
231
|
}
|
|
@@ -243,43 +236,43 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
243
236
|
// NOTE: consider some TS magic for this
|
|
244
237
|
switch (field) {
|
|
245
238
|
case 'comment':
|
|
246
|
-
this
|
|
239
|
+
this.findOptions.comment = value as string | Document;
|
|
247
240
|
break;
|
|
248
241
|
|
|
249
242
|
case 'explain':
|
|
250
|
-
this
|
|
243
|
+
this.findOptions.explain = value as boolean;
|
|
251
244
|
break;
|
|
252
245
|
|
|
253
246
|
case 'hint':
|
|
254
|
-
this
|
|
247
|
+
this.findOptions.hint = value as string | Document;
|
|
255
248
|
break;
|
|
256
249
|
|
|
257
250
|
case 'max':
|
|
258
|
-
this
|
|
251
|
+
this.findOptions.max = value as Document;
|
|
259
252
|
break;
|
|
260
253
|
|
|
261
254
|
case 'maxTimeMS':
|
|
262
|
-
this
|
|
255
|
+
this.findOptions.maxTimeMS = value as number;
|
|
263
256
|
break;
|
|
264
257
|
|
|
265
258
|
case 'min':
|
|
266
|
-
this
|
|
259
|
+
this.findOptions.min = value as Document;
|
|
267
260
|
break;
|
|
268
261
|
|
|
269
262
|
case 'orderby':
|
|
270
|
-
this
|
|
263
|
+
this.findOptions.sort = formatSort(value as string | Document);
|
|
271
264
|
break;
|
|
272
265
|
|
|
273
266
|
case 'query':
|
|
274
|
-
this
|
|
267
|
+
this.cursorFilter = value as Document;
|
|
275
268
|
break;
|
|
276
269
|
|
|
277
270
|
case 'returnKey':
|
|
278
|
-
this
|
|
271
|
+
this.findOptions.returnKey = value as boolean;
|
|
279
272
|
break;
|
|
280
273
|
|
|
281
274
|
case 'showDiskLoc':
|
|
282
|
-
this
|
|
275
|
+
this.findOptions.showRecordId = value as boolean;
|
|
283
276
|
break;
|
|
284
277
|
|
|
285
278
|
default:
|
|
@@ -295,8 +288,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
295
288
|
* @param value - The comment attached to this query.
|
|
296
289
|
*/
|
|
297
290
|
comment(value: string): this {
|
|
298
|
-
|
|
299
|
-
this
|
|
291
|
+
this.throwIfInitialized();
|
|
292
|
+
this.findOptions.comment = value;
|
|
300
293
|
return this;
|
|
301
294
|
}
|
|
302
295
|
|
|
@@ -306,12 +299,12 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
306
299
|
* @param value - Number of milliseconds to wait before aborting the tailed query.
|
|
307
300
|
*/
|
|
308
301
|
maxAwaitTimeMS(value: number): this {
|
|
309
|
-
|
|
302
|
+
this.throwIfInitialized();
|
|
310
303
|
if (typeof value !== 'number') {
|
|
311
304
|
throw new MongoInvalidArgumentError('Argument for maxAwaitTimeMS must be a number');
|
|
312
305
|
}
|
|
313
306
|
|
|
314
|
-
this
|
|
307
|
+
this.findOptions.maxAwaitTimeMS = value;
|
|
315
308
|
return this;
|
|
316
309
|
}
|
|
317
310
|
|
|
@@ -321,12 +314,12 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
321
314
|
* @param value - Number of milliseconds to wait before aborting the query.
|
|
322
315
|
*/
|
|
323
316
|
override maxTimeMS(value: number): this {
|
|
324
|
-
|
|
317
|
+
this.throwIfInitialized();
|
|
325
318
|
if (typeof value !== 'number') {
|
|
326
319
|
throw new MongoInvalidArgumentError('Argument for maxTimeMS must be a number');
|
|
327
320
|
}
|
|
328
321
|
|
|
329
|
-
this
|
|
322
|
+
this.findOptions.maxTimeMS = value;
|
|
330
323
|
return this;
|
|
331
324
|
}
|
|
332
325
|
|
|
@@ -371,8 +364,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
371
364
|
* ```
|
|
372
365
|
*/
|
|
373
366
|
project<T extends Document = Document>(value: Document): FindCursor<T> {
|
|
374
|
-
|
|
375
|
-
this
|
|
367
|
+
this.throwIfInitialized();
|
|
368
|
+
this.findOptions.projection = value;
|
|
376
369
|
return this as unknown as FindCursor<T>;
|
|
377
370
|
}
|
|
378
371
|
|
|
@@ -383,12 +376,12 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
383
376
|
* @param direction - The direction of the sorting (1 or -1).
|
|
384
377
|
*/
|
|
385
378
|
sort(sort: Sort | string, direction?: SortDirection): this {
|
|
386
|
-
|
|
387
|
-
if (this
|
|
379
|
+
this.throwIfInitialized();
|
|
380
|
+
if (this.findOptions.tailable) {
|
|
388
381
|
throw new MongoTailableCursorError('Tailable cursor does not support sorting');
|
|
389
382
|
}
|
|
390
383
|
|
|
391
|
-
this
|
|
384
|
+
this.findOptions.sort = formatSort(sort, direction);
|
|
392
385
|
return this;
|
|
393
386
|
}
|
|
394
387
|
|
|
@@ -399,19 +392,19 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
399
392
|
* {@link https://www.mongodb.com/docs/manual/reference/command/find/#find-cmd-allowdiskuse | find command allowDiskUse documentation}
|
|
400
393
|
*/
|
|
401
394
|
allowDiskUse(allow = true): this {
|
|
402
|
-
|
|
395
|
+
this.throwIfInitialized();
|
|
403
396
|
|
|
404
|
-
if (!this
|
|
397
|
+
if (!this.findOptions.sort) {
|
|
405
398
|
throw new MongoInvalidArgumentError('Option "allowDiskUse" requires a sort specification');
|
|
406
399
|
}
|
|
407
400
|
|
|
408
401
|
// As of 6.0 the default is true. This allows users to get back to the old behavior.
|
|
409
402
|
if (!allow) {
|
|
410
|
-
this
|
|
403
|
+
this.findOptions.allowDiskUse = false;
|
|
411
404
|
return this;
|
|
412
405
|
}
|
|
413
406
|
|
|
414
|
-
this
|
|
407
|
+
this.findOptions.allowDiskUse = true;
|
|
415
408
|
return this;
|
|
416
409
|
}
|
|
417
410
|
|
|
@@ -421,8 +414,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
421
414
|
* @param value - The cursor collation options (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
|
422
415
|
*/
|
|
423
416
|
collation(value: CollationOptions): this {
|
|
424
|
-
|
|
425
|
-
this
|
|
417
|
+
this.throwIfInitialized();
|
|
418
|
+
this.findOptions.collation = value;
|
|
426
419
|
return this;
|
|
427
420
|
}
|
|
428
421
|
|
|
@@ -432,8 +425,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
432
425
|
* @param value - The limit for the cursor query.
|
|
433
426
|
*/
|
|
434
427
|
limit(value: number): this {
|
|
435
|
-
|
|
436
|
-
if (this
|
|
428
|
+
this.throwIfInitialized();
|
|
429
|
+
if (this.findOptions.tailable) {
|
|
437
430
|
throw new MongoTailableCursorError('Tailable cursor does not support limit');
|
|
438
431
|
}
|
|
439
432
|
|
|
@@ -441,7 +434,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
441
434
|
throw new MongoInvalidArgumentError('Operation "limit" requires an integer');
|
|
442
435
|
}
|
|
443
436
|
|
|
444
|
-
this
|
|
437
|
+
this.findOptions.limit = value;
|
|
445
438
|
return this;
|
|
446
439
|
}
|
|
447
440
|
|
|
@@ -451,8 +444,8 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
451
444
|
* @param value - The skip for the cursor query.
|
|
452
445
|
*/
|
|
453
446
|
skip(value: number): this {
|
|
454
|
-
|
|
455
|
-
if (this
|
|
447
|
+
this.throwIfInitialized();
|
|
448
|
+
if (this.findOptions.tailable) {
|
|
456
449
|
throw new MongoTailableCursorError('Tailable cursor does not support skip');
|
|
457
450
|
}
|
|
458
451
|
|
|
@@ -460,7 +453,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
460
453
|
throw new MongoInvalidArgumentError('Operation "skip" requires an integer');
|
|
461
454
|
}
|
|
462
455
|
|
|
463
|
-
this
|
|
456
|
+
this.findOptions.skip = value;
|
|
464
457
|
return this;
|
|
465
458
|
}
|
|
466
459
|
}
|