mongodb 6.5.0 → 6.6.0-dev.20240504.sha.2609953
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 +9 -9
- package/lib/admin.js +9 -9
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +33 -22
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +13 -12
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +28 -18
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +2 -2
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +6 -6
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/providers/aws.js +13 -10
- package/lib/client-side-encryption/providers/aws.js.map +1 -1
- package/lib/client-side-encryption/providers/azure.js +6 -3
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js +140 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +7 -6
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +8 -101
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
- package/lib/cmap/auth/scram.js +2 -2
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/commands.js +24 -111
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +4 -4
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +61 -36
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +22 -13
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +2 -2
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +8 -8
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js +218 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +184 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/collection.js +42 -38
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +4 -6
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +76 -43
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +16 -33
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +36 -18
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +3 -2
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +15 -19
- package/lib/db.js.map +1 -1
- package/lib/deps.js +31 -26
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +14 -5
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +4 -3
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +19 -14
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +6 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +11 -7
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +3 -0
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/aggregate.js +2 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/create_collection.js +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +4 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/execute_operation.js +23 -8
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +4 -4
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/get_more.js +2 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +29 -121
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/kill_cursors.js +3 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/run_command.js +4 -2
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/search_indexes/create.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/monitor.js +139 -42
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +5 -15
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +1 -0
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +1 -1
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +67 -54
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +10 -0
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +133 -93
- package/lib/sessions.js.map +1 -1
- package/lib/timeout.js +77 -0
- package/lib/timeout.js.map +1 -0
- package/lib/utils.js +61 -28
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +150 -38
- package/package.json +17 -14
- package/src/admin.ts +9 -9
- package/src/bson.ts +14 -0
- package/src/bulk/common.ts +3 -2
- package/src/change_stream.ts +39 -30
- package/src/client-side-encryption/auto_encrypter.ts +2 -2
- package/src/client-side-encryption/client_encryption.ts +6 -6
- package/src/client-side-encryption/providers/aws.ts +17 -10
- package/src/client-side-encryption/providers/azure.ts +5 -3
- package/src/cmap/auth/aws_temporary_credentials.ts +169 -0
- package/src/cmap/auth/gssapi.ts +9 -11
- package/src/cmap/auth/mongodb_aws.ts +19 -126
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
- package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
- package/src/cmap/auth/scram.ts +2 -2
- package/src/cmap/commands.ts +28 -132
- package/src/cmap/connect.ts +4 -4
- package/src/cmap/connection.ts +107 -43
- package/src/cmap/connection_pool.ts +32 -29
- package/src/cmap/handshake/client_metadata.ts +2 -5
- package/src/cmap/wire_protocol/compression.ts +11 -13
- package/src/cmap/wire_protocol/on_demand/document.ts +338 -0
- package/src/cmap/wire_protocol/responses.ts +237 -0
- package/src/collection.ts +87 -58
- package/src/connection_string.ts +9 -7
- package/src/cursor/abstract_cursor.ts +102 -38
- package/src/cursor/aggregation_cursor.ts +32 -34
- package/src/cursor/find_cursor.ts +33 -21
- package/src/cursor/list_search_indexes_cursor.ts +1 -1
- package/src/cursor/run_command_cursor.ts +3 -2
- package/src/db.ts +42 -21
- package/src/deps.ts +52 -40
- package/src/encrypter.ts +14 -5
- package/src/error.ts +9 -3
- package/src/gridfs/download.ts +19 -31
- package/src/gridfs/index.ts +2 -0
- package/src/gridfs/upload.ts +11 -8
- package/src/index.ts +13 -5
- package/src/mongo_client.ts +21 -15
- package/src/mongo_logger.ts +3 -0
- package/src/mongo_types.ts +1 -1
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/command.ts +1 -1
- package/src/operations/create_collection.ts +7 -2
- package/src/operations/delete.ts +4 -3
- package/src/operations/drop.ts +1 -1
- package/src/operations/execute_operation.ts +29 -10
- package/src/operations/find.ts +13 -14
- package/src/operations/get_more.ts +9 -1
- package/src/operations/indexes.ts +103 -176
- package/src/operations/insert.ts +2 -2
- package/src/operations/kill_cursors.ts +3 -2
- package/src/operations/list_collections.ts +5 -1
- package/src/operations/list_databases.ts +1 -1
- package/src/operations/operation.ts +3 -0
- package/src/operations/run_command.ts +6 -4
- package/src/operations/search_indexes/create.ts +4 -1
- package/src/operations/stats.ts +1 -1
- package/src/operations/update.ts +7 -7
- package/src/sdam/common.ts +8 -2
- package/src/sdam/monitor.ts +178 -61
- package/src/sdam/server.ts +27 -20
- package/src/sdam/server_description.ts +8 -3
- package/src/sdam/server_selection.ts +2 -3
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +114 -117
- package/src/sdam/topology_description.ts +14 -4
- package/src/sessions.ts +168 -148
- package/src/timeout.ts +96 -0
- package/src/utils.ts +85 -32
- package/lib/operations/common_functions.js +0 -38
- package/lib/operations/common_functions.js.map +0 -1
- package/src/operations/common_functions.ts +0 -79
package/src/mongo_client.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
2
|
import type { TcpNetConnectOpts } from 'net';
|
|
3
3
|
import type { ConnectionOptions as TLSConnectionOptions, TLSSocketOptions } from 'tls';
|
|
4
|
-
import { promisify } from 'util';
|
|
5
4
|
|
|
6
5
|
import { type BSONSerializeOptions, type Document, resolveBSONOptions } from './bson';
|
|
7
6
|
import { ChangeStream, type ChangeStreamDocument, type ChangeStreamOptions } from './change_stream';
|
|
@@ -50,7 +49,8 @@ import {
|
|
|
50
49
|
isHostMatch,
|
|
51
50
|
type MongoDBNamespace,
|
|
52
51
|
ns,
|
|
53
|
-
resolveOptions
|
|
52
|
+
resolveOptions,
|
|
53
|
+
squashError
|
|
54
54
|
} from './utils';
|
|
55
55
|
import type { W, WriteConcern, WriteConcernSettings } from './write_concern';
|
|
56
56
|
|
|
@@ -120,7 +120,7 @@ export type SupportedNodeConnectionOptions = SupportedTLSConnectionOptions &
|
|
|
120
120
|
export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeConnectionOptions {
|
|
121
121
|
/** Specifies the name of the replica set, if the mongod is a member of a replica set. */
|
|
122
122
|
replicaSet?: string;
|
|
123
|
-
/** @internal This option is in development and currently has no behaviour.
|
|
123
|
+
/** @internal TODO(NODE-5688): This option is in development and currently has no behaviour. */
|
|
124
124
|
timeoutMS?: number;
|
|
125
125
|
/** Enables or disables TLS/SSL for the connection. */
|
|
126
126
|
tls?: boolean;
|
|
@@ -469,7 +469,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
469
469
|
*/
|
|
470
470
|
async connect(): Promise<this> {
|
|
471
471
|
if (this.connectionLock) {
|
|
472
|
-
return this.connectionLock;
|
|
472
|
+
return await this.connectionLock;
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
try {
|
|
@@ -550,7 +550,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
550
550
|
|
|
551
551
|
const topologyConnect = async () => {
|
|
552
552
|
try {
|
|
553
|
-
await
|
|
553
|
+
await this.topology?.connect(options);
|
|
554
554
|
} catch (error) {
|
|
555
555
|
this.topology?.close();
|
|
556
556
|
throw error;
|
|
@@ -600,13 +600,17 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
600
600
|
if (servers.length !== 0) {
|
|
601
601
|
const endSessions = Array.from(this.s.sessionPool.sessions, ({ id }) => id);
|
|
602
602
|
if (endSessions.length !== 0) {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
603
|
+
try {
|
|
604
|
+
await executeOperation(
|
|
605
|
+
this,
|
|
606
|
+
new RunAdminCommandOperation(
|
|
607
|
+
{ endSessions },
|
|
608
|
+
{ readPreference: ReadPreference.primaryPreferred, noResponse: true }
|
|
609
|
+
)
|
|
610
|
+
);
|
|
611
|
+
} catch (error) {
|
|
612
|
+
squashError(error);
|
|
613
|
+
}
|
|
610
614
|
}
|
|
611
615
|
}
|
|
612
616
|
|
|
@@ -656,7 +660,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
656
660
|
*/
|
|
657
661
|
static async connect(url: string, options?: MongoClientOptions): Promise<MongoClient> {
|
|
658
662
|
const client = new this(url, options);
|
|
659
|
-
return client.connect();
|
|
663
|
+
return await client.connect();
|
|
660
664
|
}
|
|
661
665
|
|
|
662
666
|
/**
|
|
@@ -718,8 +722,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
718
722
|
} finally {
|
|
719
723
|
try {
|
|
720
724
|
await session.endSession();
|
|
721
|
-
} catch {
|
|
722
|
-
|
|
725
|
+
} catch (error) {
|
|
726
|
+
squashError(error);
|
|
723
727
|
}
|
|
724
728
|
}
|
|
725
729
|
}
|
|
@@ -893,4 +897,6 @@ export interface MongoOptions
|
|
|
893
897
|
* TODO: NODE-5671 - remove internal flag
|
|
894
898
|
*/
|
|
895
899
|
mongodbLogPath?: 'stderr' | 'stdout' | MongoDBLogWritable;
|
|
900
|
+
/** @internal TODO(NODE-5688): make this public */
|
|
901
|
+
timeoutMS?: number;
|
|
896
902
|
}
|
package/src/mongo_logger.ts
CHANGED
|
@@ -836,7 +836,9 @@ export class MongoLogger {
|
|
|
836
836
|
|
|
837
837
|
if (isPromiseLike(this.pendingLog)) {
|
|
838
838
|
this.pendingLog = this.pendingLog
|
|
839
|
+
// eslint-disable-next-line github/no-then
|
|
839
840
|
.then(() => this.logDestination.write(logMessage))
|
|
841
|
+
// eslint-disable-next-line github/no-then
|
|
840
842
|
.then(this.clearPendingLog.bind(this), this.logWriteFailureHandler.bind(this));
|
|
841
843
|
return;
|
|
842
844
|
}
|
|
@@ -844,6 +846,7 @@ export class MongoLogger {
|
|
|
844
846
|
try {
|
|
845
847
|
const logResult = this.logDestination.write(logMessage);
|
|
846
848
|
if (isPromiseLike(logResult)) {
|
|
849
|
+
// eslint-disable-next-line github/no-then
|
|
847
850
|
this.pendingLog = logResult.then(
|
|
848
851
|
this.clearPendingLog.bind(this),
|
|
849
852
|
this.logWriteFailureHandler.bind(this)
|
package/src/mongo_types.ts
CHANGED
|
@@ -219,7 +219,7 @@ export type NotAcceptedFields<TSchema, FieldType> = {
|
|
|
219
219
|
/** @public */
|
|
220
220
|
export type OnlyFieldsOfType<TSchema, FieldType = any, AssignableType = FieldType> = IsAny<
|
|
221
221
|
TSchema[keyof TSchema],
|
|
222
|
-
Record<string, FieldType>,
|
|
222
|
+
AssignableType extends FieldType ? Record<string, FieldType> : Record<string, AssignableType>,
|
|
223
223
|
AcceptedFields<TSchema, FieldType, AssignableType> &
|
|
224
224
|
NotAcceptedFields<TSchema, FieldType> &
|
|
225
225
|
Record<string, AssignableType>
|
|
@@ -134,7 +134,8 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
134
134
|
command.cursor.batchSize = options.batchSize;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
const res: TODO_NODE_3286 = await super.executeCommand(server, session, command);
|
|
138
|
+
return res;
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
|
|
@@ -10,7 +10,7 @@ import type { PkFactory } from '../mongo_client';
|
|
|
10
10
|
import type { Server } from '../sdam/server';
|
|
11
11
|
import type { ClientSession } from '../sessions';
|
|
12
12
|
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
13
|
-
import {
|
|
13
|
+
import { CreateIndexesOperation } from './indexes';
|
|
14
14
|
import { Aspect, defineAspects } from './operation';
|
|
15
15
|
|
|
16
16
|
const ILLEGAL_COMMAND_FIELDS = new Set([
|
|
@@ -167,7 +167,12 @@ export class CreateCollectionOperation extends CommandOperation<Collection> {
|
|
|
167
167
|
|
|
168
168
|
if (encryptedFields) {
|
|
169
169
|
// Create the required index for queryable encryption support.
|
|
170
|
-
const createIndexOp =
|
|
170
|
+
const createIndexOp = CreateIndexesOperation.fromIndexSpecification(
|
|
171
|
+
db,
|
|
172
|
+
name,
|
|
173
|
+
{ __safeContent__: 1 },
|
|
174
|
+
{}
|
|
175
|
+
);
|
|
171
176
|
await createIndexOp.execute(server, session);
|
|
172
177
|
}
|
|
173
178
|
|
package/src/operations/delete.ts
CHANGED
|
@@ -95,7 +95,8 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
const res: TODO_NODE_3286 = await super.executeCommand(server, session, command);
|
|
99
|
+
return res;
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
|
|
@@ -108,7 +109,7 @@ export class DeleteOneOperation extends DeleteOperation {
|
|
|
108
109
|
server: Server,
|
|
109
110
|
session: ClientSession | undefined
|
|
110
111
|
): Promise<DeleteResult> {
|
|
111
|
-
const res =
|
|
112
|
+
const res: TODO_NODE_3286 = await super.execute(server, session);
|
|
112
113
|
if (this.explain) return res;
|
|
113
114
|
if (res.code) throw new MongoServerError(res);
|
|
114
115
|
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
@@ -128,7 +129,7 @@ export class DeleteManyOperation extends DeleteOperation {
|
|
|
128
129
|
server: Server,
|
|
129
130
|
session: ClientSession | undefined
|
|
130
131
|
): Promise<DeleteResult> {
|
|
131
|
-
const res =
|
|
132
|
+
const res: TODO_NODE_3286 = await super.execute(server, session);
|
|
132
133
|
if (this.explain) return res;
|
|
133
134
|
if (res.code) throw new MongoServerError(res);
|
|
134
135
|
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
package/src/operations/drop.ts
CHANGED
|
@@ -69,7 +69,7 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
return this.executeWithoutEncryptedFieldsCheck(server, session);
|
|
72
|
+
return await this.executeWithoutEncryptedFieldsCheck(server, session);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
private async executeWithoutEncryptedFieldsCheck(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
|
+
import { type CursorResponse } from '../cmap/wire_protocol/responses';
|
|
2
3
|
import {
|
|
3
4
|
isRetryableReadError,
|
|
4
5
|
isRetryableWriteError,
|
|
@@ -26,7 +27,7 @@ import {
|
|
|
26
27
|
} from '../sdam/server_selection';
|
|
27
28
|
import type { Topology } from '../sdam/topology';
|
|
28
29
|
import type { ClientSession } from '../sessions';
|
|
29
|
-
import { supportsRetryableWrites } from '../utils';
|
|
30
|
+
import { squashError, supportsRetryableWrites } from '../utils';
|
|
30
31
|
import { AbstractOperation, Aspect } from './operation';
|
|
31
32
|
|
|
32
33
|
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
|
|
@@ -44,7 +45,7 @@ export interface ExecutionResult {
|
|
|
44
45
|
/** The session used for this operation, may be implicitly created */
|
|
45
46
|
session?: ClientSession;
|
|
46
47
|
/** The raw server response for the operation */
|
|
47
|
-
response: Document;
|
|
48
|
+
response: Document | CursorResponse;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/**
|
|
@@ -110,11 +111,23 @@ export async function executeOperation<
|
|
|
110
111
|
} else if (session.client !== client) {
|
|
111
112
|
throw new MongoInvalidArgumentError('ClientSession must be from the same MongoClient');
|
|
112
113
|
}
|
|
114
|
+
if (session.explicit && session?.timeoutMS != null && operation.options.timeoutMS != null) {
|
|
115
|
+
throw new MongoInvalidArgumentError(
|
|
116
|
+
'Do not specify timeoutMS on operation if already specified on an explicit session'
|
|
117
|
+
);
|
|
118
|
+
}
|
|
113
119
|
|
|
114
120
|
const readPreference = operation.readPreference ?? ReadPreference.primary;
|
|
115
121
|
const inTransaction = !!session?.inTransaction();
|
|
116
122
|
|
|
117
|
-
|
|
123
|
+
const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
|
|
124
|
+
const hasWriteAspect = operation.hasAspect(Aspect.WRITE_OPERATION);
|
|
125
|
+
|
|
126
|
+
if (
|
|
127
|
+
inTransaction &&
|
|
128
|
+
!readPreference.equals(ReadPreference.primary) &&
|
|
129
|
+
(hasReadAspect || operation.commandName === 'runCommand')
|
|
130
|
+
) {
|
|
118
131
|
throw new MongoTransactionError(
|
|
119
132
|
`Read preference in a transaction must be primary, not: ${readPreference.mode}`
|
|
120
133
|
);
|
|
@@ -139,14 +152,14 @@ export async function executeOperation<
|
|
|
139
152
|
selector = readPreference;
|
|
140
153
|
}
|
|
141
154
|
|
|
142
|
-
const server = await topology.
|
|
155
|
+
const server = await topology.selectServer(selector, {
|
|
143
156
|
session,
|
|
144
157
|
operationName: operation.commandName
|
|
145
158
|
});
|
|
146
159
|
|
|
147
160
|
if (session == null) {
|
|
148
161
|
// No session also means it is not retryable, early exit
|
|
149
|
-
return operation.execute(server, undefined);
|
|
162
|
+
return await operation.execute(server, undefined);
|
|
150
163
|
}
|
|
151
164
|
|
|
152
165
|
if (!operation.hasAspect(Aspect.RETRYABLE)) {
|
|
@@ -155,7 +168,11 @@ export async function executeOperation<
|
|
|
155
168
|
return await operation.execute(server, session);
|
|
156
169
|
} finally {
|
|
157
170
|
if (session?.owner != null && session.owner === owner) {
|
|
158
|
-
|
|
171
|
+
try {
|
|
172
|
+
await session.endSession();
|
|
173
|
+
} catch (error) {
|
|
174
|
+
squashError(error);
|
|
175
|
+
}
|
|
159
176
|
}
|
|
160
177
|
}
|
|
161
178
|
}
|
|
@@ -168,8 +185,6 @@ export async function executeOperation<
|
|
|
168
185
|
supportsRetryableWrites(server) &&
|
|
169
186
|
operation.canRetryWrite;
|
|
170
187
|
|
|
171
|
-
const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
|
|
172
|
-
const hasWriteAspect = operation.hasAspect(Aspect.WRITE_OPERATION);
|
|
173
188
|
const willRetry = (hasReadAspect && willRetryRead) || (hasWriteAspect && willRetryWrite);
|
|
174
189
|
|
|
175
190
|
if (hasWriteAspect && willRetryWrite) {
|
|
@@ -191,7 +206,11 @@ export async function executeOperation<
|
|
|
191
206
|
throw operationError;
|
|
192
207
|
} finally {
|
|
193
208
|
if (session?.owner != null && session.owner === owner) {
|
|
194
|
-
|
|
209
|
+
try {
|
|
210
|
+
await session.endSession();
|
|
211
|
+
} catch (error) {
|
|
212
|
+
squashError(error);
|
|
213
|
+
}
|
|
195
214
|
}
|
|
196
215
|
}
|
|
197
216
|
}
|
|
@@ -244,7 +263,7 @@ async function retryOperation<
|
|
|
244
263
|
}
|
|
245
264
|
|
|
246
265
|
// select a new server, and attempt to retry the operation
|
|
247
|
-
const server = await topology.
|
|
266
|
+
const server = await topology.selectServer(selector, {
|
|
248
267
|
session,
|
|
249
268
|
operationName: operation.commandName,
|
|
250
269
|
previousServer
|
package/src/operations/find.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
|
-
import type { Collection } from '../collection';
|
|
3
2
|
import { MongoInvalidArgumentError } from '../error';
|
|
4
3
|
import { ReadConcern } from '../read_concern';
|
|
5
4
|
import type { Server } from '../sdam/server';
|
|
@@ -77,13 +76,8 @@ export class FindOperation extends CommandOperation<Document> {
|
|
|
77
76
|
override options: FindOptions & { writeConcern?: never };
|
|
78
77
|
filter: Document;
|
|
79
78
|
|
|
80
|
-
constructor(
|
|
81
|
-
|
|
82
|
-
ns: MongoDBNamespace,
|
|
83
|
-
filter: Document = {},
|
|
84
|
-
options: FindOptions = {}
|
|
85
|
-
) {
|
|
86
|
-
super(collection, options);
|
|
79
|
+
constructor(ns: MongoDBNamespace, filter: Document = {}, options: FindOptions = {}) {
|
|
80
|
+
super(undefined, options);
|
|
87
81
|
|
|
88
82
|
this.options = { ...options };
|
|
89
83
|
delete this.options.writeConcern;
|
|
@@ -111,12 +105,17 @@ export class FindOperation extends CommandOperation<Document> {
|
|
|
111
105
|
findCommand = decorateWithExplain(findCommand, this.explain);
|
|
112
106
|
}
|
|
113
107
|
|
|
114
|
-
return server.command(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
return await server.command(
|
|
109
|
+
this.ns,
|
|
110
|
+
findCommand,
|
|
111
|
+
{
|
|
112
|
+
...this.options,
|
|
113
|
+
...this.bsonOptions,
|
|
114
|
+
documentsReturnedIn: 'firstBatch',
|
|
115
|
+
session
|
|
116
|
+
},
|
|
117
|
+
undefined
|
|
118
|
+
);
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Document, Long } from '../bson';
|
|
2
|
+
import { CursorResponse } from '../cmap/wire_protocol/responses';
|
|
2
3
|
import { MongoRuntimeError } from '../error';
|
|
3
4
|
import type { Server } from '../sdam/server';
|
|
4
5
|
import type { ClientSession } from '../sessions';
|
|
@@ -19,6 +20,8 @@ export interface GetMoreOptions extends OperationOptions {
|
|
|
19
20
|
maxTimeMS?: number;
|
|
20
21
|
/** TODO(NODE-4413): Address bug with maxAwaitTimeMS not being passed in from the cursor correctly */
|
|
21
22
|
maxAwaitTimeMS?: number;
|
|
23
|
+
|
|
24
|
+
useCursorResponse: boolean;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -96,7 +99,12 @@ export class GetMoreOperation extends AbstractOperation {
|
|
|
96
99
|
...this.options
|
|
97
100
|
};
|
|
98
101
|
|
|
99
|
-
return server.command(
|
|
102
|
+
return await server.command(
|
|
103
|
+
this.ns,
|
|
104
|
+
getMoreCmd,
|
|
105
|
+
commandOptions,
|
|
106
|
+
this.options.useCursorResponse ? CursorResponse : undefined
|
|
107
|
+
);
|
|
100
108
|
}
|
|
101
109
|
}
|
|
102
110
|
|