mongodb 6.7.0 → 6.8.0-dev.20240629.sha.d85f827a
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/README.md +29 -1
- package/lib/bson.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +8 -61
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +5 -5
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/providers/index.js.map +1 -1
- package/lib/client-side-encryption/state_machine.js +15 -11
- package/lib/client-side-encryption/state_machine.js.map +1 -1
- package/lib/cmap/connection.js +22 -20
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +2 -2
- package/lib/cmap/wire_protocol/on_demand/document.js +8 -5
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
- package/lib/cmap/wire_protocol/responses.js +116 -40
- package/lib/cmap/wire_protocol/responses.js.map +1 -1
- package/lib/collection.js +13 -2
- package/lib/collection.js.map +1 -1
- package/lib/constants.js +9 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +231 -285
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +11 -19
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/change_stream_cursor.js +12 -14
- package/lib/cursor/change_stream_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +64 -84
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/list_collections_cursor.js +0 -1
- package/lib/cursor/list_collections_cursor.js.map +1 -1
- package/lib/cursor/list_indexes_cursor.js +0 -1
- package/lib/cursor/list_indexes_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +4 -6
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/error.js +10 -23
- package/lib/error.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/operations/aggregate.js +2 -2
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js +1 -2
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/command.js +2 -3
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +2 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/get_more.js +1 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +2 -1
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/list_collections.js +2 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/run_command.js +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/update.js +2 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/server.js +7 -2
- package/lib/sdam/server.js.map +1 -1
- package/lib/sessions.js +1 -1
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +45 -1
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js +17 -1
- package/lib/write_concern.js.map +1 -1
- package/mongodb.d.ts +188 -221
- package/package.json +3 -3
- package/src/bson.ts +1 -0
- package/src/client-side-encryption/auto_encrypter.ts +10 -149
- package/src/client-side-encryption/client_encryption.ts +33 -19
- package/src/client-side-encryption/providers/index.ts +118 -92
- package/src/client-side-encryption/state_machine.ts +22 -18
- package/src/cmap/connection.ts +46 -50
- package/src/cmap/wire_protocol/constants.ts +2 -2
- package/src/cmap/wire_protocol/on_demand/document.ts +13 -6
- package/src/cmap/wire_protocol/responses.ts +140 -45
- package/src/collection.ts +25 -5
- package/src/constants.ts +9 -0
- package/src/cursor/abstract_cursor.ts +280 -373
- package/src/cursor/aggregation_cursor.ts +24 -33
- package/src/cursor/change_stream_cursor.ts +31 -48
- package/src/cursor/find_cursor.ts +77 -92
- package/src/cursor/list_collections_cursor.ts +3 -4
- package/src/cursor/list_indexes_cursor.ts +3 -4
- package/src/cursor/run_command_cursor.ts +13 -19
- package/src/error.ts +20 -30
- package/src/index.ts +19 -10
- package/src/operations/aggregate.ts +12 -5
- package/src/operations/bulk_write.ts +1 -2
- package/src/operations/command.ts +17 -3
- package/src/operations/delete.ts +2 -2
- package/src/operations/execute_operation.ts +0 -13
- package/src/operations/find.ts +7 -3
- package/src/operations/find_and_modify.ts +1 -1
- package/src/operations/get_more.ts +6 -10
- package/src/operations/indexes.ts +7 -3
- package/src/operations/list_collections.ts +8 -3
- package/src/operations/run_command.ts +16 -6
- package/src/operations/update.ts +2 -1
- package/src/sdam/server.ts +7 -2
- package/src/sessions.ts +1 -1
- package/src/utils.ts +52 -2
- package/src/write_concern.ts +18 -0
- package/lib/operations/count_documents.js +0 -31
- package/lib/operations/count_documents.js.map +0 -1
- package/src/operations/count_documents.ts +0 -46
|
@@ -2,22 +2,17 @@ import type { Document } from '../bson';
|
|
|
2
2
|
import type { ExplainVerbosityLike } from '../explain';
|
|
3
3
|
import type { MongoClient } from '../mongo_client';
|
|
4
4
|
import { AggregateOperation, type AggregateOptions } from '../operations/aggregate';
|
|
5
|
-
import { executeOperation
|
|
5
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
6
6
|
import type { ClientSession } from '../sessions';
|
|
7
7
|
import type { Sort } from '../sort';
|
|
8
8
|
import type { MongoDBNamespace } from '../utils';
|
|
9
9
|
import { mergeOptions } from '../utils';
|
|
10
|
-
import type { AbstractCursorOptions } from './abstract_cursor';
|
|
11
|
-
import { AbstractCursor
|
|
10
|
+
import type { AbstractCursorOptions, InitialCursorResponse } from './abstract_cursor';
|
|
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
|
}
|
|
@@ -61,29 +51,30 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
61
51
|
}
|
|
62
52
|
|
|
63
53
|
/** @internal */
|
|
64
|
-
async _initialize(session: ClientSession): Promise<
|
|
65
|
-
const aggregateOperation = new AggregateOperation(this.namespace, this
|
|
66
|
-
...this
|
|
54
|
+
async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
|
|
55
|
+
const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, {
|
|
56
|
+
...this.aggregateOptions,
|
|
67
57
|
...this.cursorOptions,
|
|
68
58
|
session
|
|
69
59
|
});
|
|
70
60
|
|
|
71
61
|
const response = await executeOperation(this.client, aggregateOperation);
|
|
72
62
|
|
|
73
|
-
// TODO: NODE-2882
|
|
74
63
|
return { server: aggregateOperation.server, session, response };
|
|
75
64
|
}
|
|
76
65
|
|
|
77
66
|
/** Execute the explain for the cursor */
|
|
78
67
|
async explain(verbosity?: ExplainVerbosityLike): Promise<Document> {
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
68
|
+
return (
|
|
69
|
+
await executeOperation(
|
|
70
|
+
this.client,
|
|
71
|
+
new AggregateOperation(this.namespace, this.pipeline, {
|
|
72
|
+
...this.aggregateOptions, // NOTE: order matters here, we may need to refine this
|
|
73
|
+
...this.cursorOptions,
|
|
74
|
+
explain: verbosity ?? true
|
|
75
|
+
})
|
|
76
|
+
)
|
|
77
|
+
).shift(this.aggregateOptions);
|
|
87
78
|
}
|
|
88
79
|
|
|
89
80
|
/** Add a stage to the aggregation pipeline
|
|
@@ -101,8 +92,8 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
101
92
|
addStage(stage: Document): this;
|
|
102
93
|
addStage<T = Document>(stage: Document): AggregationCursor<T>;
|
|
103
94
|
addStage<T = Document>(stage: Document): AggregationCursor<T> {
|
|
104
|
-
|
|
105
|
-
this
|
|
95
|
+
this.throwIfInitialized();
|
|
96
|
+
this.pipeline.push(stage);
|
|
106
97
|
return this as unknown as AggregationCursor<T>;
|
|
107
98
|
}
|
|
108
99
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Document
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
2
|
import {
|
|
3
3
|
ChangeStream,
|
|
4
4
|
type ChangeStreamDocument,
|
|
@@ -6,15 +6,19 @@ import {
|
|
|
6
6
|
type OperationTime,
|
|
7
7
|
type ResumeToken
|
|
8
8
|
} from '../change_stream';
|
|
9
|
+
import { type CursorResponse } from '../cmap/wire_protocol/responses';
|
|
9
10
|
import { INIT, RESPONSE } from '../constants';
|
|
10
11
|
import type { MongoClient } from '../mongo_client';
|
|
11
|
-
import type { TODO_NODE_3286 } from '../mongo_types';
|
|
12
12
|
import { AggregateOperation } from '../operations/aggregate';
|
|
13
13
|
import type { CollationOptions } from '../operations/command';
|
|
14
|
-
import { executeOperation
|
|
14
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
15
15
|
import type { ClientSession } from '../sessions';
|
|
16
16
|
import { maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
AbstractCursor,
|
|
19
|
+
type AbstractCursorOptions,
|
|
20
|
+
type InitialCursorResponse
|
|
21
|
+
} from './abstract_cursor';
|
|
18
22
|
|
|
19
23
|
/** @internal */
|
|
20
24
|
export interface ChangeStreamCursorOptions extends AbstractCursorOptions {
|
|
@@ -26,32 +30,17 @@ export interface ChangeStreamCursorOptions extends AbstractCursorOptions {
|
|
|
26
30
|
fullDocument?: string;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
/** @internal */
|
|
30
|
-
export type ChangeStreamAggregateRawResult<TChange> = {
|
|
31
|
-
$clusterTime: { clusterTime: Timestamp };
|
|
32
|
-
cursor: {
|
|
33
|
-
postBatchResumeToken: ResumeToken;
|
|
34
|
-
ns: string;
|
|
35
|
-
id: number | Long;
|
|
36
|
-
} & ({ firstBatch: TChange[] } | { nextBatch: TChange[] });
|
|
37
|
-
ok: 1;
|
|
38
|
-
operationTime: Timestamp;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
33
|
/** @internal */
|
|
42
34
|
export class ChangeStreamCursor<
|
|
43
35
|
TSchema extends Document = Document,
|
|
44
36
|
TChange extends Document = ChangeStreamDocument<TSchema>
|
|
45
37
|
> extends AbstractCursor<TChange, ChangeStreamEvents> {
|
|
46
|
-
_resumeToken: ResumeToken;
|
|
47
|
-
startAtOperationTime
|
|
48
|
-
hasReceived?: boolean;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
postBatchResumeToken?: ResumeToken;
|
|
54
|
-
pipeline: Document[];
|
|
38
|
+
private _resumeToken: ResumeToken;
|
|
39
|
+
private startAtOperationTime: OperationTime | null;
|
|
40
|
+
private hasReceived?: boolean;
|
|
41
|
+
private readonly changeStreamCursorOptions: ChangeStreamCursorOptions;
|
|
42
|
+
private postBatchResumeToken?: ResumeToken;
|
|
43
|
+
private readonly pipeline: Document[];
|
|
55
44
|
|
|
56
45
|
/**
|
|
57
46
|
* @internal
|
|
@@ -69,9 +58,9 @@ export class ChangeStreamCursor<
|
|
|
69
58
|
super(client, namespace, options);
|
|
70
59
|
|
|
71
60
|
this.pipeline = pipeline;
|
|
72
|
-
this.
|
|
61
|
+
this.changeStreamCursorOptions = options;
|
|
73
62
|
this._resumeToken = null;
|
|
74
|
-
this.startAtOperationTime = options.startAtOperationTime;
|
|
63
|
+
this.startAtOperationTime = options.startAtOperationTime ?? null;
|
|
75
64
|
|
|
76
65
|
if (options.startAfter) {
|
|
77
66
|
this.resumeToken = options.startAfter;
|
|
@@ -91,7 +80,7 @@ export class ChangeStreamCursor<
|
|
|
91
80
|
|
|
92
81
|
get resumeOptions(): ChangeStreamCursorOptions {
|
|
93
82
|
const options: ChangeStreamCursorOptions = {
|
|
94
|
-
...this.
|
|
83
|
+
...this.changeStreamCursorOptions
|
|
95
84
|
};
|
|
96
85
|
|
|
97
86
|
for (const key of ['resumeAfter', 'startAfter', 'startAtOperationTime'] as const) {
|
|
@@ -99,7 +88,7 @@ export class ChangeStreamCursor<
|
|
|
99
88
|
}
|
|
100
89
|
|
|
101
90
|
if (this.resumeToken != null) {
|
|
102
|
-
if (this.
|
|
91
|
+
if (this.changeStreamCursorOptions.startAfter && !this.hasReceived) {
|
|
103
92
|
options.startAfter = this.resumeToken;
|
|
104
93
|
} else {
|
|
105
94
|
options.resumeAfter = this.resumeToken;
|
|
@@ -120,15 +109,13 @@ export class ChangeStreamCursor<
|
|
|
120
109
|
this.hasReceived = true;
|
|
121
110
|
}
|
|
122
111
|
|
|
123
|
-
_processBatch(response:
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
126
|
-
this.postBatchResumeToken =
|
|
112
|
+
_processBatch(response: CursorResponse): void {
|
|
113
|
+
const { postBatchResumeToken } = response;
|
|
114
|
+
if (postBatchResumeToken) {
|
|
115
|
+
this.postBatchResumeToken = postBatchResumeToken;
|
|
127
116
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (batch.length === 0) {
|
|
131
|
-
this.resumeToken = cursor.postBatchResumeToken;
|
|
117
|
+
if (response.batchSize === 0) {
|
|
118
|
+
this.resumeToken = postBatchResumeToken;
|
|
132
119
|
}
|
|
133
120
|
}
|
|
134
121
|
}
|
|
@@ -139,25 +126,22 @@ export class ChangeStreamCursor<
|
|
|
139
126
|
});
|
|
140
127
|
}
|
|
141
128
|
|
|
142
|
-
async _initialize(session: ClientSession): Promise<
|
|
129
|
+
async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
|
|
143
130
|
const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, {
|
|
144
131
|
...this.cursorOptions,
|
|
145
|
-
...this.
|
|
132
|
+
...this.changeStreamCursorOptions,
|
|
146
133
|
session
|
|
147
134
|
});
|
|
148
135
|
|
|
149
|
-
const response = await executeOperation
|
|
150
|
-
TODO_NODE_3286,
|
|
151
|
-
ChangeStreamAggregateRawResult<TChange>
|
|
152
|
-
>(session.client, aggregateOperation);
|
|
136
|
+
const response = await executeOperation(session.client, aggregateOperation);
|
|
153
137
|
|
|
154
138
|
const server = aggregateOperation.server;
|
|
155
139
|
this.maxWireVersion = maxWireVersion(server);
|
|
156
140
|
|
|
157
141
|
if (
|
|
158
142
|
this.startAtOperationTime == null &&
|
|
159
|
-
this.resumeAfter == null &&
|
|
160
|
-
this.startAfter == null &&
|
|
143
|
+
this.changeStreamCursorOptions.resumeAfter == null &&
|
|
144
|
+
this.changeStreamCursorOptions.startAfter == null &&
|
|
161
145
|
this.maxWireVersion >= 7
|
|
162
146
|
) {
|
|
163
147
|
this.startAtOperationTime = response.operationTime;
|
|
@@ -168,15 +152,14 @@ export class ChangeStreamCursor<
|
|
|
168
152
|
this.emit(INIT, response);
|
|
169
153
|
this.emit(RESPONSE);
|
|
170
154
|
|
|
171
|
-
// TODO: NODE-2882
|
|
172
155
|
return { server, session, response };
|
|
173
156
|
}
|
|
174
157
|
|
|
175
|
-
override async getMore(batchSize: number): Promise<
|
|
158
|
+
override async getMore(batchSize: number): Promise<CursorResponse> {
|
|
176
159
|
const response = await super.getMore(batchSize);
|
|
177
160
|
|
|
178
161
|
this.maxWireVersion = maxWireVersion(this.server);
|
|
179
|
-
this._processBatch(response
|
|
162
|
+
this._processBatch(response);
|
|
180
163
|
|
|
181
164
|
this.emit(ChangeStream.MORE, response);
|
|
182
165
|
this.emit(ChangeStream.RESPONSE);
|