mongodb 6.7.0-dev.20240608.sha.0655c730 → 6.7.0-dev.20240614.sha.3ed6a2ad
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/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/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/constants.js +9 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +24 -60
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +2 -3
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/change_stream_cursor.js +6 -8
- package/lib/cursor/change_stream_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +5 -17
- 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 +6 -21
- 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/count_documents.js +1 -7
- package/lib/operations/count_documents.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/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 +120 -85
- package/package.json +1 -1
- package/src/bson.ts +1 -0
- package/src/client-side-encryption/auto_encrypter.ts +9 -70
- package/src/client-side-encryption/client_encryption.ts +6 -6
- package/src/client-side-encryption/providers/index.ts +120 -92
- package/src/client-side-encryption/state_machine.ts +22 -18
- package/src/cmap/connection.ts +46 -50
- package/src/cmap/wire_protocol/on_demand/document.ts +13 -6
- package/src/cmap/wire_protocol/responses.ts +140 -45
- package/src/constants.ts +9 -0
- package/src/cursor/abstract_cursor.ts +51 -71
- package/src/cursor/aggregation_cursor.ts +13 -12
- package/src/cursor/change_stream_cursor.ts +20 -34
- package/src/cursor/find_cursor.ts +17 -25
- 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 +16 -28
- package/src/index.ts +12 -8
- 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/count_documents.ts +7 -11
- 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/utils.ts +52 -2
- package/src/write_concern.ts +18 -0
|
@@ -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,25 +30,13 @@ 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
38
|
private _resumeToken: ResumeToken;
|
|
47
|
-
private startAtOperationTime
|
|
39
|
+
private startAtOperationTime: OperationTime | null;
|
|
48
40
|
private hasReceived?: boolean;
|
|
49
41
|
private readonly changeStreamCursorOptions: ChangeStreamCursorOptions;
|
|
50
42
|
private postBatchResumeToken?: ResumeToken;
|
|
@@ -68,7 +60,7 @@ export class ChangeStreamCursor<
|
|
|
68
60
|
this.pipeline = pipeline;
|
|
69
61
|
this.changeStreamCursorOptions = options;
|
|
70
62
|
this._resumeToken = null;
|
|
71
|
-
this.startAtOperationTime = options.startAtOperationTime;
|
|
63
|
+
this.startAtOperationTime = options.startAtOperationTime ?? null;
|
|
72
64
|
|
|
73
65
|
if (options.startAfter) {
|
|
74
66
|
this.resumeToken = options.startAfter;
|
|
@@ -117,15 +109,13 @@ export class ChangeStreamCursor<
|
|
|
117
109
|
this.hasReceived = true;
|
|
118
110
|
}
|
|
119
111
|
|
|
120
|
-
_processBatch(response:
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
this.postBatchResumeToken =
|
|
112
|
+
_processBatch(response: CursorResponse): void {
|
|
113
|
+
const { postBatchResumeToken } = response;
|
|
114
|
+
if (postBatchResumeToken) {
|
|
115
|
+
this.postBatchResumeToken = postBatchResumeToken;
|
|
124
116
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (batch.length === 0) {
|
|
128
|
-
this.resumeToken = cursor.postBatchResumeToken;
|
|
117
|
+
if (response.batchSize === 0) {
|
|
118
|
+
this.resumeToken = postBatchResumeToken;
|
|
129
119
|
}
|
|
130
120
|
}
|
|
131
121
|
}
|
|
@@ -136,17 +126,14 @@ export class ChangeStreamCursor<
|
|
|
136
126
|
});
|
|
137
127
|
}
|
|
138
128
|
|
|
139
|
-
async _initialize(session: ClientSession): Promise<
|
|
129
|
+
async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
|
|
140
130
|
const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, {
|
|
141
131
|
...this.cursorOptions,
|
|
142
132
|
...this.changeStreamCursorOptions,
|
|
143
133
|
session
|
|
144
134
|
});
|
|
145
135
|
|
|
146
|
-
const response = await executeOperation
|
|
147
|
-
TODO_NODE_3286,
|
|
148
|
-
ChangeStreamAggregateRawResult<TChange>
|
|
149
|
-
>(session.client, aggregateOperation);
|
|
136
|
+
const response = await executeOperation(session.client, aggregateOperation);
|
|
150
137
|
|
|
151
138
|
const server = aggregateOperation.server;
|
|
152
139
|
this.maxWireVersion = maxWireVersion(server);
|
|
@@ -165,15 +152,14 @@ export class ChangeStreamCursor<
|
|
|
165
152
|
this.emit(INIT, response);
|
|
166
153
|
this.emit(RESPONSE);
|
|
167
154
|
|
|
168
|
-
// TODO: NODE-2882
|
|
169
155
|
return { server, session, response };
|
|
170
156
|
}
|
|
171
157
|
|
|
172
|
-
override async getMore(batchSize: number): Promise<
|
|
158
|
+
override async getMore(batchSize: number): Promise<CursorResponse> {
|
|
173
159
|
const response = await super.getMore(batchSize);
|
|
174
160
|
|
|
175
161
|
this.maxWireVersion = maxWireVersion(this.server);
|
|
176
|
-
this._processBatch(response
|
|
162
|
+
this._processBatch(response);
|
|
177
163
|
|
|
178
164
|
this.emit(ChangeStream.MORE, response);
|
|
179
165
|
this.emit(ChangeStream.RESPONSE);
|
|
@@ -5,13 +5,13 @@ import { type ExplainVerbosityLike } from '../explain';
|
|
|
5
5
|
import type { MongoClient } from '../mongo_client';
|
|
6
6
|
import type { CollationOptions } from '../operations/command';
|
|
7
7
|
import { CountOperation, type CountOptions } from '../operations/count';
|
|
8
|
-
import { executeOperation
|
|
8
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
9
9
|
import { FindOperation, type FindOptions } from '../operations/find';
|
|
10
10
|
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 } from './abstract_cursor';
|
|
14
|
+
import { AbstractCursor, type InitialCursorResponse } from './abstract_cursor';
|
|
15
15
|
|
|
16
16
|
/** @public Flags allowed for cursor */
|
|
17
17
|
export const FLAGS = [
|
|
@@ -62,7 +62,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/** @internal */
|
|
65
|
-
async _initialize(session: ClientSession): Promise<
|
|
65
|
+
async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
|
|
66
66
|
const findOperation = new FindOperation(this.namespace, this.cursorFilter, {
|
|
67
67
|
...this.findOptions, // NOTE: order matters here, we may need to refine this
|
|
68
68
|
...this.cursorOptions,
|
|
@@ -72,19 +72,13 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
72
72
|
const response = await executeOperation(this.client, findOperation);
|
|
73
73
|
|
|
74
74
|
// the response is not a cursor when `explain` is enabled
|
|
75
|
-
|
|
76
|
-
this.numReturned = response.batchSize;
|
|
77
|
-
} else {
|
|
78
|
-
// Can be an explain response, hence the ?. on everything
|
|
79
|
-
this.numReturned = this.numReturned + (response?.cursor?.firstBatch?.length ?? 0);
|
|
80
|
-
}
|
|
75
|
+
this.numReturned = response.batchSize;
|
|
81
76
|
|
|
82
|
-
// TODO: NODE-2882
|
|
83
77
|
return { server: findOperation.server, session, response };
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
/** @internal */
|
|
87
|
-
override async getMore(batchSize: number): Promise<
|
|
81
|
+
override async getMore(batchSize: number): Promise<CursorResponse> {
|
|
88
82
|
const numReturned = this.numReturned;
|
|
89
83
|
if (numReturned) {
|
|
90
84
|
// TODO(DRIVERS-1448): Remove logic to enforce `limit` in the driver
|
|
@@ -110,13 +104,9 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
110
104
|
}
|
|
111
105
|
}
|
|
112
106
|
|
|
113
|
-
const response = await super.getMore(batchSize
|
|
107
|
+
const response = await super.getMore(batchSize);
|
|
114
108
|
// TODO: wrap this in some logic to prevent it from happening if we don't need this support
|
|
115
|
-
|
|
116
|
-
this.numReturned = this.numReturned + response.batchSize;
|
|
117
|
-
} else {
|
|
118
|
-
this.numReturned = this.numReturned + (response?.cursor?.nextBatch?.length ?? 0);
|
|
119
|
-
}
|
|
109
|
+
this.numReturned = this.numReturned + response.batchSize;
|
|
120
110
|
|
|
121
111
|
return response;
|
|
122
112
|
}
|
|
@@ -144,14 +134,16 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
144
134
|
|
|
145
135
|
/** Execute the explain for the cursor */
|
|
146
136
|
async explain(verbosity?: ExplainVerbosityLike): Promise<Document> {
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
137
|
+
return (
|
|
138
|
+
await executeOperation(
|
|
139
|
+
this.client,
|
|
140
|
+
new FindOperation(this.namespace, this.cursorFilter, {
|
|
141
|
+
...this.findOptions, // NOTE: order matters here, we may need to refine this
|
|
142
|
+
...this.cursorOptions,
|
|
143
|
+
explain: verbosity ?? true
|
|
144
|
+
})
|
|
145
|
+
)
|
|
146
|
+
).shift(this.findOptions);
|
|
155
147
|
}
|
|
156
148
|
|
|
157
149
|
/** Set the cursor query */
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
2
|
import type { Db } from '../db';
|
|
3
|
-
import { executeOperation
|
|
3
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
4
4
|
import {
|
|
5
5
|
type CollectionInfo,
|
|
6
6
|
ListCollectionsOperation,
|
|
7
7
|
type ListCollectionsOptions
|
|
8
8
|
} from '../operations/list_collections';
|
|
9
9
|
import type { ClientSession } from '../sessions';
|
|
10
|
-
import { AbstractCursor } from './abstract_cursor';
|
|
10
|
+
import { AbstractCursor, type InitialCursorResponse } from './abstract_cursor';
|
|
11
11
|
|
|
12
12
|
/** @public */
|
|
13
13
|
export class ListCollectionsCursor<
|
|
@@ -34,7 +34,7 @@ export class ListCollectionsCursor<
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** @internal */
|
|
37
|
-
async _initialize(session: ClientSession | undefined): Promise<
|
|
37
|
+
async _initialize(session: ClientSession | undefined): Promise<InitialCursorResponse> {
|
|
38
38
|
const operation = new ListCollectionsOperation(this.parent, this.filter, {
|
|
39
39
|
...this.cursorOptions,
|
|
40
40
|
...this.options,
|
|
@@ -43,7 +43,6 @@ export class ListCollectionsCursor<
|
|
|
43
43
|
|
|
44
44
|
const response = await executeOperation(this.parent.client, operation);
|
|
45
45
|
|
|
46
|
-
// TODO: NODE-2882
|
|
47
46
|
return { server: operation.server, session, response };
|
|
48
47
|
}
|
|
49
48
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Collection } from '../collection';
|
|
2
|
-
import { executeOperation
|
|
2
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
3
3
|
import { ListIndexesOperation, type ListIndexesOptions } from '../operations/indexes';
|
|
4
4
|
import type { ClientSession } from '../sessions';
|
|
5
|
-
import { AbstractCursor } from './abstract_cursor';
|
|
5
|
+
import { AbstractCursor, type InitialCursorResponse } from './abstract_cursor';
|
|
6
6
|
|
|
7
7
|
/** @public */
|
|
8
8
|
export class ListIndexesCursor extends AbstractCursor {
|
|
@@ -23,7 +23,7 @@ export class ListIndexesCursor extends AbstractCursor {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** @internal */
|
|
26
|
-
async _initialize(session: ClientSession | undefined): Promise<
|
|
26
|
+
async _initialize(session: ClientSession | undefined): Promise<InitialCursorResponse> {
|
|
27
27
|
const operation = new ListIndexesOperation(this.parent, {
|
|
28
28
|
...this.cursorOptions,
|
|
29
29
|
...this.options,
|
|
@@ -32,7 +32,6 @@ export class ListIndexesCursor extends AbstractCursor {
|
|
|
32
32
|
|
|
33
33
|
const response = await executeOperation(this.parent.client, operation);
|
|
34
34
|
|
|
35
|
-
// TODO: NODE-2882
|
|
36
35
|
return { server: operation.server, session, response };
|
|
37
36
|
}
|
|
38
37
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { BSONSerializeOptions, Document
|
|
1
|
+
import type { BSONSerializeOptions, Document } from '../bson';
|
|
2
|
+
import { CursorResponse } from '../cmap/wire_protocol/responses';
|
|
2
3
|
import type { Db } from '../db';
|
|
3
|
-
import { MongoAPIError
|
|
4
|
-
import { executeOperation
|
|
4
|
+
import { MongoAPIError } from '../error';
|
|
5
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
5
6
|
import { GetMoreOperation } from '../operations/get_more';
|
|
6
7
|
import { RunCommandOperation } from '../operations/run_command';
|
|
7
8
|
import type { ReadConcernLike } from '../read_concern';
|
|
8
9
|
import type { ReadPreferenceLike } from '../read_preference';
|
|
9
10
|
import type { ClientSession } from '../sessions';
|
|
10
11
|
import { ns } from '../utils';
|
|
11
|
-
import { AbstractCursor } from './abstract_cursor';
|
|
12
|
+
import { AbstractCursor, type InitialCursorResponse } from './abstract_cursor';
|
|
12
13
|
|
|
13
14
|
/** @public */
|
|
14
15
|
export type RunCursorCommandOptions = {
|
|
@@ -16,12 +17,6 @@ export type RunCursorCommandOptions = {
|
|
|
16
17
|
session?: ClientSession;
|
|
17
18
|
} & BSONSerializeOptions;
|
|
18
19
|
|
|
19
|
-
/** @internal */
|
|
20
|
-
type RunCursorCommandResponse = {
|
|
21
|
-
cursor: { id: bigint | Long | number; ns: string; firstBatch: Document[] };
|
|
22
|
-
ok: 1;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
20
|
/** @public */
|
|
26
21
|
export class RunCommandCursor extends AbstractCursor {
|
|
27
22
|
public readonly command: Readonly<Record<string, any>>;
|
|
@@ -102,16 +97,16 @@ export class RunCommandCursor extends AbstractCursor {
|
|
|
102
97
|
}
|
|
103
98
|
|
|
104
99
|
/** @internal */
|
|
105
|
-
protected async _initialize(session: ClientSession): Promise<
|
|
106
|
-
const operation = new RunCommandOperation<
|
|
100
|
+
protected async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
|
|
101
|
+
const operation = new RunCommandOperation<CursorResponse>(this.db, this.command, {
|
|
107
102
|
...this.cursorOptions,
|
|
108
103
|
session: session,
|
|
109
|
-
readPreference: this.cursorOptions.readPreference
|
|
104
|
+
readPreference: this.cursorOptions.readPreference,
|
|
105
|
+
responseType: CursorResponse
|
|
110
106
|
});
|
|
107
|
+
|
|
111
108
|
const response = await executeOperation(this.client, operation);
|
|
112
|
-
|
|
113
|
-
throw new MongoUnexpectedServerResponseError('Expected server to respond with cursor');
|
|
114
|
-
}
|
|
109
|
+
|
|
115
110
|
return {
|
|
116
111
|
server: operation.server,
|
|
117
112
|
session,
|
|
@@ -120,13 +115,12 @@ export class RunCommandCursor extends AbstractCursor {
|
|
|
120
115
|
}
|
|
121
116
|
|
|
122
117
|
/** @internal */
|
|
123
|
-
override async getMore(_batchSize: number): Promise<
|
|
118
|
+
override async getMore(_batchSize: number): Promise<CursorResponse> {
|
|
124
119
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
125
120
|
const getMoreOperation = new GetMoreOperation(this.namespace, this.id!, this.server!, {
|
|
126
121
|
...this.cursorOptions,
|
|
127
122
|
session: this.session,
|
|
128
|
-
...this.getMoreOptions
|
|
129
|
-
useCursorResponse: false
|
|
123
|
+
...this.getMoreOptions
|
|
130
124
|
});
|
|
131
125
|
|
|
132
126
|
return await executeOperation(this.client, getMoreOperation);
|
package/src/error.ts
CHANGED
|
@@ -750,8 +750,8 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError {
|
|
|
750
750
|
*
|
|
751
751
|
* @public
|
|
752
752
|
**/
|
|
753
|
-
constructor(message: string) {
|
|
754
|
-
super(message);
|
|
753
|
+
constructor(message: string, options?: { cause?: Error }) {
|
|
754
|
+
super(message, options);
|
|
755
755
|
}
|
|
756
756
|
|
|
757
757
|
override get name(): string {
|
|
@@ -1157,27 +1157,14 @@ export class MongoServerSelectionError extends MongoSystemError {
|
|
|
1157
1157
|
}
|
|
1158
1158
|
}
|
|
1159
1159
|
|
|
1160
|
-
function makeWriteConcernResultObject(input: any) {
|
|
1161
|
-
const output = Object.assign({}, input);
|
|
1162
|
-
|
|
1163
|
-
if (output.ok === 0) {
|
|
1164
|
-
output.ok = 1;
|
|
1165
|
-
delete output.errmsg;
|
|
1166
|
-
delete output.code;
|
|
1167
|
-
delete output.codeName;
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
return output;
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
1160
|
/**
|
|
1174
1161
|
* An error thrown when the server reports a writeConcernError
|
|
1175
1162
|
* @public
|
|
1176
1163
|
* @category Error
|
|
1177
1164
|
*/
|
|
1178
1165
|
export class MongoWriteConcernError extends MongoServerError {
|
|
1179
|
-
/** The result document
|
|
1180
|
-
result
|
|
1166
|
+
/** The result document */
|
|
1167
|
+
result: Document;
|
|
1181
1168
|
|
|
1182
1169
|
/**
|
|
1183
1170
|
* **Do not use this constructor!**
|
|
@@ -1190,17 +1177,18 @@ export class MongoWriteConcernError extends MongoServerError {
|
|
|
1190
1177
|
*
|
|
1191
1178
|
* @public
|
|
1192
1179
|
**/
|
|
1193
|
-
constructor(
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1180
|
+
constructor(result: {
|
|
1181
|
+
writeConcernError: {
|
|
1182
|
+
code: number;
|
|
1183
|
+
errmsg: string;
|
|
1184
|
+
codeName?: string;
|
|
1185
|
+
errInfo?: Document;
|
|
1186
|
+
};
|
|
1187
|
+
errorLabels?: string[];
|
|
1188
|
+
}) {
|
|
1189
|
+
super({ ...result, ...result.writeConcernError });
|
|
1190
|
+
this.errInfo = result.writeConcernError.errInfo;
|
|
1191
|
+
this.result = result;
|
|
1204
1192
|
}
|
|
1205
1193
|
|
|
1206
1194
|
override get name(): string {
|
package/src/index.ts
CHANGED
|
@@ -160,7 +160,7 @@ export { SrvPollingEvent } from './sdam/srv_polling';
|
|
|
160
160
|
|
|
161
161
|
// type only exports below, these are removed from emitted JS
|
|
162
162
|
export type { AdminPrivate } from './admin';
|
|
163
|
-
export type { BSONSerializeOptions, Document } from './bson';
|
|
163
|
+
export type { BSONElement, BSONSerializeOptions, Document } from './bson';
|
|
164
164
|
export type { deserialize, serialize } from './bson';
|
|
165
165
|
export type {
|
|
166
166
|
BulkResult,
|
|
@@ -238,8 +238,13 @@ export {
|
|
|
238
238
|
} from './client-side-encryption/errors';
|
|
239
239
|
export type { MongocryptdManager } from './client-side-encryption/mongocryptd_manager';
|
|
240
240
|
export type {
|
|
241
|
+
AWSKMSProviderConfiguration,
|
|
242
|
+
AzureKMSProviderConfiguration,
|
|
241
243
|
ClientEncryptionDataKeyProvider,
|
|
242
|
-
|
|
244
|
+
GCPKMSProviderConfiguration,
|
|
245
|
+
KMIPKMSProviderConfiguration,
|
|
246
|
+
KMSProviders,
|
|
247
|
+
LocalKMSProviderConfiguration
|
|
243
248
|
} from './client-side-encryption/providers/index';
|
|
244
249
|
export type {
|
|
245
250
|
ClientEncryptionTlsOptions,
|
|
@@ -337,12 +342,12 @@ export type {
|
|
|
337
342
|
CursorFlag,
|
|
338
343
|
CursorStreamOptions
|
|
339
344
|
} from './cursor/abstract_cursor';
|
|
340
|
-
export type { InternalAbstractCursorOptions } from './cursor/abstract_cursor';
|
|
341
|
-
export type { AggregationCursorOptions } from './cursor/aggregation_cursor';
|
|
342
345
|
export type {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
} from './cursor/
|
|
346
|
+
InitialCursorResponse,
|
|
347
|
+
InternalAbstractCursorOptions
|
|
348
|
+
} from './cursor/abstract_cursor';
|
|
349
|
+
export type { AggregationCursorOptions } from './cursor/aggregation_cursor';
|
|
350
|
+
export type { ChangeStreamCursorOptions } from './cursor/change_stream_cursor';
|
|
346
351
|
export type {
|
|
347
352
|
ListSearchIndexesCursor,
|
|
348
353
|
ListSearchIndexesOptions
|
|
@@ -468,7 +473,6 @@ export type { DeleteOptions, DeleteResult, DeleteStatement } from './operations/
|
|
|
468
473
|
export type { DistinctOptions } from './operations/distinct';
|
|
469
474
|
export type { DropCollectionOptions, DropDatabaseOptions } from './operations/drop';
|
|
470
475
|
export type { EstimatedDocumentCountOptions } from './operations/estimated_document_count';
|
|
471
|
-
export type { ExecutionResult } from './operations/execute_operation';
|
|
472
476
|
export type { FindOptions } from './operations/find';
|
|
473
477
|
export type {
|
|
474
478
|
FindOneAndDeleteOptions,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
|
+
import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
|
|
2
3
|
import { MongoInvalidArgumentError } from '../error';
|
|
3
|
-
import { type TODO_NODE_3286 } from '../mongo_types';
|
|
4
4
|
import type { Server } from '../sdam/server';
|
|
5
5
|
import type { ClientSession } from '../sessions';
|
|
6
6
|
import { maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
@@ -37,7 +37,7 @@ export interface AggregateOptions extends CommandOperationOptions {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/** @internal */
|
|
40
|
-
export class AggregateOperation
|
|
40
|
+
export class AggregateOperation extends CommandOperation<CursorResponse> {
|
|
41
41
|
override options: AggregateOptions;
|
|
42
42
|
target: string | typeof DB_AGGREGATE_COLLECTION;
|
|
43
43
|
pipeline: Document[];
|
|
@@ -94,7 +94,10 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
94
94
|
this.pipeline.push(stage);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
override async execute(
|
|
97
|
+
override async execute(
|
|
98
|
+
server: Server,
|
|
99
|
+
session: ClientSession | undefined
|
|
100
|
+
): Promise<CursorResponse> {
|
|
98
101
|
const options: AggregateOptions = this.options;
|
|
99
102
|
const serverWireVersion = maxWireVersion(server);
|
|
100
103
|
const command: Document = { aggregate: this.target, pipeline: this.pipeline };
|
|
@@ -134,8 +137,12 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
134
137
|
command.cursor.batchSize = options.batchSize;
|
|
135
138
|
}
|
|
136
139
|
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
return await super.executeCommand(
|
|
141
|
+
server,
|
|
142
|
+
session,
|
|
143
|
+
command,
|
|
144
|
+
this.explain ? ExplainedCursorResponse : CursorResponse
|
|
145
|
+
);
|
|
139
146
|
}
|
|
140
147
|
}
|
|
141
148
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BSONSerializeOptions, Document } from '../bson';
|
|
2
|
+
import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses';
|
|
2
3
|
import { MongoInvalidArgumentError } from '../error';
|
|
3
4
|
import { Explain, type ExplainOptions } from '../explain';
|
|
4
5
|
import { ReadConcern } from '../read_concern';
|
|
@@ -106,12 +107,25 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
|
|
|
106
107
|
return true;
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
async executeCommand(
|
|
110
|
+
public async executeCommand<T extends MongoDBResponseConstructor>(
|
|
111
|
+
server: Server,
|
|
112
|
+
session: ClientSession | undefined,
|
|
113
|
+
cmd: Document,
|
|
114
|
+
responseType: T | undefined
|
|
115
|
+
): Promise<typeof responseType extends undefined ? Document : InstanceType<T>>;
|
|
116
|
+
|
|
117
|
+
public async executeCommand(
|
|
110
118
|
server: Server,
|
|
111
119
|
session: ClientSession | undefined,
|
|
112
120
|
cmd: Document
|
|
121
|
+
): Promise<Document>;
|
|
122
|
+
|
|
123
|
+
async executeCommand(
|
|
124
|
+
server: Server,
|
|
125
|
+
session: ClientSession | undefined,
|
|
126
|
+
cmd: Document,
|
|
127
|
+
responseType?: MongoDBResponseConstructor
|
|
113
128
|
): Promise<Document> {
|
|
114
|
-
// TODO: consider making this a non-enumerable property
|
|
115
129
|
this.server = server;
|
|
116
130
|
|
|
117
131
|
const options = {
|
|
@@ -152,6 +166,6 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
|
|
|
152
166
|
cmd = decorateWithExplain(cmd, this.explain);
|
|
153
167
|
}
|
|
154
168
|
|
|
155
|
-
return await server.command(this.ns, cmd, options);
|
|
169
|
+
return await server.command(this.ns, cmd, options, responseType);
|
|
156
170
|
}
|
|
157
171
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
2
|
import type { Collection } from '../collection';
|
|
3
|
+
import { type TODO_NODE_3286 } from '../mongo_types';
|
|
3
4
|
import type { Server } from '../sdam/server';
|
|
4
5
|
import type { ClientSession } from '../sessions';
|
|
5
6
|
import { AggregateOperation, type AggregateOptions } from './aggregate';
|
|
@@ -13,7 +14,7 @@ export interface CountDocumentsOptions extends AggregateOptions {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/** @internal */
|
|
16
|
-
export class CountDocumentsOperation extends AggregateOperation
|
|
17
|
+
export class CountDocumentsOperation extends AggregateOperation {
|
|
17
18
|
constructor(collection: Collection, query: Document, options: CountDocumentsOptions) {
|
|
18
19
|
const pipeline = [];
|
|
19
20
|
pipeline.push({ $match: query });
|
|
@@ -31,16 +32,11 @@ export class CountDocumentsOperation extends AggregateOperation<number> {
|
|
|
31
32
|
super(collection.s.namespace, pipeline, options);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
override async execute(
|
|
35
|
+
override async execute(
|
|
36
|
+
server: Server,
|
|
37
|
+
session: ClientSession | undefined
|
|
38
|
+
): Promise<TODO_NODE_3286> {
|
|
35
39
|
const result = await super.execute(server, session);
|
|
36
|
-
|
|
37
|
-
// NOTE: We're avoiding creating a cursor here to reduce the callstack.
|
|
38
|
-
const response = result as unknown as Document;
|
|
39
|
-
if (response.cursor == null || response.cursor.firstBatch == null) {
|
|
40
|
-
return 0;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const docs = response.cursor.firstBatch;
|
|
44
|
-
return docs.length ? docs[0].n : 0;
|
|
40
|
+
return result.shift()?.n ?? 0;
|
|
45
41
|
}
|
|
46
42
|
}
|
package/src/operations/delete.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { MongoCompatibilityError, MongoServerError } from '../error';
|
|
|
4
4
|
import { type TODO_NODE_3286 } from '../mongo_types';
|
|
5
5
|
import type { Server } from '../sdam/server';
|
|
6
6
|
import type { ClientSession } from '../sessions';
|
|
7
|
-
import type
|
|
8
|
-
import type
|
|
7
|
+
import { type MongoDBNamespace } from '../utils';
|
|
8
|
+
import { type WriteConcernOptions } from '../write_concern';
|
|
9
9
|
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
|
|
10
10
|
import { Aspect, defineAspects, type Hint } from './operation';
|
|
11
11
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Document } from '../bson';
|
|
2
|
-
import { type CursorResponse } from '../cmap/wire_protocol/responses';
|
|
3
1
|
import {
|
|
4
2
|
isRetryableReadError,
|
|
5
3
|
isRetryableWriteError,
|
|
@@ -18,7 +16,6 @@ import {
|
|
|
18
16
|
} from '../error';
|
|
19
17
|
import type { MongoClient } from '../mongo_client';
|
|
20
18
|
import { ReadPreference } from '../read_preference';
|
|
21
|
-
import type { Server } from '../sdam/server';
|
|
22
19
|
import type { ServerDescription } from '../sdam/server_description';
|
|
23
20
|
import {
|
|
24
21
|
sameServerSelector,
|
|
@@ -38,16 +35,6 @@ type ResultTypeFromOperation<TOperation> = TOperation extends AbstractOperation<
|
|
|
38
35
|
? K
|
|
39
36
|
: never;
|
|
40
37
|
|
|
41
|
-
/** @internal */
|
|
42
|
-
export interface ExecutionResult {
|
|
43
|
-
/** The server selected for the operation */
|
|
44
|
-
server: Server;
|
|
45
|
-
/** The session used for this operation, may be implicitly created */
|
|
46
|
-
session?: ClientSession;
|
|
47
|
-
/** The raw server response for the operation */
|
|
48
|
-
response: Document | CursorResponse;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
38
|
/**
|
|
52
39
|
* Executes the given operation with provided arguments.
|
|
53
40
|
* @internal
|