mongodb 4.2.0 → 4.3.1
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 +2 -2
- package/lib/admin.js +3 -3
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +16 -14
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +7 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js +1 -1
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +6 -7
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +3 -3
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +24 -26
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +2 -2
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +6 -6
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/providers.js +21 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +4 -4
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +3 -2
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +20 -11
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +119 -31
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +36 -35
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +19 -30
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js +3 -3
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +4 -4
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +2 -1
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +4 -3
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +45 -47
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +48 -23
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +113 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +10 -7
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +23 -13
- package/lib/db.js.map +1 -1
- package/lib/deps.js +0 -1
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +12 -4
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +47 -24
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +1 -1
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +3 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +3 -2
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +81 -81
- package/lib/index.js.map +1 -1
- package/lib/logger.js +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +5 -5
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +3 -3
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +1 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js +5 -6
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +4 -13
- package/lib/operations/connect.js.map +1 -1
- package/lib/operations/count.js +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/create_collection.js +3 -2
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +3 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +3 -3
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js +2 -2
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js +2 -2
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +15 -9
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +5 -5
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +2 -2
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +28 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +4 -4
- 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/is_capped.js +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +3 -3
- 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/map_reduce.js +4 -3
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +3 -2
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js +1 -1
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/remove_user.js +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +3 -3
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/run_command.js +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/set_profiling_level.js +2 -2
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +2 -2
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_preference.js +15 -5
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/events.js +4 -4
- package/lib/sdam/monitor.js +19 -18
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +24 -31
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +38 -38
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +19 -3
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -2
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +32 -62
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +3 -3
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +13 -28
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +46 -15
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +145 -61
- package/mongodb.ts34.d.ts +173 -60
- package/package.json +29 -28
- package/src/admin.ts +9 -9
- package/src/bson.ts +26 -17
- package/src/bulk/common.ts +22 -23
- package/src/bulk/ordered.ts +4 -4
- package/src/bulk/unordered.ts +5 -5
- package/src/change_stream.ts +31 -28
- package/src/cmap/auth/auth_provider.ts +3 -3
- package/src/cmap/auth/gssapi.ts +8 -8
- package/src/cmap/auth/mongo_credentials.ts +11 -15
- package/src/cmap/auth/mongocr.ts +3 -2
- package/src/cmap/auth/mongodb_aws.ts +10 -11
- package/src/cmap/auth/plain.ts +1 -1
- package/src/cmap/auth/providers.ts +21 -0
- package/src/cmap/auth/scram.ts +9 -9
- package/src/cmap/auth/x509.ts +3 -3
- package/src/cmap/command_monitoring_events.ts +4 -3
- package/src/cmap/commands.ts +30 -19
- package/src/cmap/connect.ts +161 -37
- package/src/cmap/connection.ts +83 -63
- package/src/cmap/connection_pool.ts +39 -39
- package/src/cmap/connection_pool_events.ts +1 -1
- package/src/cmap/message_stream.ts +9 -8
- package/src/cmap/stream_description.ts +5 -5
- package/src/cmap/wire_protocol/compression.ts +4 -3
- package/src/cmap/wire_protocol/shared.ts +10 -9
- package/src/collection.ts +114 -95
- package/src/connection_string.ts +66 -29
- package/src/constants.ts +122 -0
- package/src/cursor/abstract_cursor.ts +21 -22
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +2 -2
- package/src/db.ts +44 -33
- package/src/deps.ts +3 -1
- package/src/encrypter.ts +12 -3
- package/src/error.ts +52 -24
- package/src/gridfs/download.ts +10 -8
- package/src/gridfs/index.ts +11 -11
- package/src/gridfs/upload.ts +13 -10
- package/src/index.ts +204 -199
- package/src/logger.ts +2 -1
- package/src/mongo_client.ts +46 -32
- package/src/mongo_types.ts +119 -21
- package/src/operations/add_user.ts +7 -6
- package/src/operations/aggregate.ts +5 -5
- package/src/operations/bulk_write.ts +5 -5
- package/src/operations/collections.ts +2 -2
- package/src/operations/command.ts +15 -9
- package/src/operations/common_functions.ts +4 -4
- package/src/operations/connect.ts +4 -14
- package/src/operations/count.ts +4 -4
- package/src/operations/count_documents.ts +3 -3
- package/src/operations/create_collection.ts +7 -6
- package/src/operations/delete.ts +5 -5
- package/src/operations/distinct.ts +4 -4
- package/src/operations/drop.ts +4 -4
- package/src/operations/estimated_document_count.ts +5 -5
- package/src/operations/eval.ts +5 -5
- package/src/operations/execute_operation.ts +21 -13
- package/src/operations/find.ts +14 -14
- package/src/operations/find_and_modify.ts +7 -7
- package/src/operations/get_more.ts +49 -0
- package/src/operations/indexes.ts +16 -16
- package/src/operations/insert.ts +9 -9
- package/src/operations/is_capped.ts +3 -3
- package/src/operations/list_collections.ts +6 -6
- package/src/operations/list_databases.ts +4 -4
- package/src/operations/map_reduce.ts +10 -9
- package/src/operations/operation.ts +5 -4
- package/src/operations/options_operation.ts +3 -3
- package/src/operations/profiling_level.ts +4 -4
- package/src/operations/remove_user.ts +4 -4
- package/src/operations/rename.ts +6 -6
- package/src/operations/run_command.ts +3 -3
- package/src/operations/set_profiling_level.ts +6 -5
- package/src/operations/stats.ts +4 -4
- package/src/operations/update.ts +10 -10
- package/src/operations/validate_collection.ts +4 -4
- package/src/read_preference.ts +18 -7
- package/src/sdam/common.ts +2 -2
- package/src/sdam/events.ts +5 -5
- package/src/sdam/monitor.ts +29 -32
- package/src/sdam/server.ts +64 -62
- package/src/sdam/server_description.ts +41 -48
- package/src/sdam/server_selection.ts +21 -3
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +71 -89
- package/src/sdam/topology_description.ts +5 -5
- package/src/sessions.ts +31 -48
- package/src/transactions.ts +4 -4
- package/src/utils.ts +69 -33
- package/lib/cmap/auth/defaultAuthProviders.js +0 -30
- package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
- package/src/cmap/auth/defaultAuthProviders.ts +0 -32
package/src/mongo_client.ts
CHANGED
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TcpNetConnectOpts } from 'net';
|
|
2
|
+
import type { ConnectionOptions as TLSConnectionOptions, TLSSocketOptions } from 'tls';
|
|
3
|
+
|
|
4
|
+
import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
|
|
2
5
|
import { ChangeStream, ChangeStreamOptions } from './change_stream';
|
|
3
|
-
import type {
|
|
6
|
+
import type { AuthMechanismProperties, MongoCredentials } from './cmap/auth/mongo_credentials';
|
|
7
|
+
import type { AuthMechanism } from './cmap/auth/providers';
|
|
8
|
+
import type { LEGAL_TCP_SOCKET_OPTIONS, LEGAL_TLS_SOCKET_OPTIONS } from './cmap/connect';
|
|
9
|
+
import type { Connection } from './cmap/connection';
|
|
10
|
+
import type { CompressorName } from './cmap/wire_protocol/compression';
|
|
11
|
+
import { parseOptions } from './connection_string';
|
|
12
|
+
import type { MONGO_CLIENT_EVENTS } from './constants';
|
|
13
|
+
import { Db, DbOptions } from './db';
|
|
14
|
+
import type { AutoEncrypter, AutoEncryptionOptions } from './deps';
|
|
15
|
+
import type { Encrypter } from './encrypter';
|
|
4
16
|
import {
|
|
5
17
|
AnyError,
|
|
6
|
-
MongoRuntimeError,
|
|
7
18
|
MongoInvalidArgumentError,
|
|
8
|
-
MongoNotConnectedError
|
|
19
|
+
MongoNotConnectedError,
|
|
20
|
+
MongoRuntimeError
|
|
9
21
|
} from './error';
|
|
10
|
-
import type {
|
|
22
|
+
import type { Logger, LoggerLevel } from './logger';
|
|
23
|
+
import { TypedEventEmitter } from './mongo_types';
|
|
24
|
+
import { connect } from './operations/connect';
|
|
25
|
+
import { PromiseProvider } from './promise_provider';
|
|
26
|
+
import type { ReadConcern, ReadConcernLevel, ReadConcernLike } from './read_concern';
|
|
27
|
+
import type { ReadPreference, ReadPreferenceMode } from './read_preference';
|
|
28
|
+
import type { TagSet } from './sdam/server_description';
|
|
29
|
+
import type { SrvPoller } from './sdam/srv_polling';
|
|
30
|
+
import type { Topology, TopologyEvents } from './sdam/topology';
|
|
31
|
+
import type { ClientSession, ClientSessionOptions } from './sessions';
|
|
11
32
|
import {
|
|
12
|
-
maybePromise,
|
|
13
|
-
MongoDBNamespace,
|
|
14
33
|
Callback,
|
|
15
|
-
resolveOptions,
|
|
16
34
|
ClientMetadata,
|
|
35
|
+
HostAddress,
|
|
36
|
+
maybePromise,
|
|
37
|
+
MongoDBNamespace,
|
|
17
38
|
ns,
|
|
18
|
-
|
|
39
|
+
resolveOptions
|
|
19
40
|
} from './utils';
|
|
20
|
-
import {
|
|
21
|
-
import { PromiseProvider } from './promise_provider';
|
|
22
|
-
import type { Logger, LoggerLevel } from './logger';
|
|
23
|
-
import type { ReadConcern, ReadConcernLevel, ReadConcernLike } from './read_concern';
|
|
24
|
-
import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
|
|
25
|
-
import type { AutoEncrypter, AutoEncryptionOptions } from './deps';
|
|
26
|
-
import type { AuthMechanism } from './cmap/auth/defaultAuthProviders';
|
|
27
|
-
import type { Topology, TopologyEvents } from './sdam/topology';
|
|
28
|
-
import type { ClientSession, ClientSessionOptions } from './sessions';
|
|
29
|
-
import type { TagSet } from './sdam/server_description';
|
|
30
|
-
import type { AuthMechanismProperties, MongoCredentials } from './cmap/auth/mongo_credentials';
|
|
31
|
-
import { parseOptions } from './connection_string';
|
|
32
|
-
import type { CompressorName } from './cmap/wire_protocol/compression';
|
|
33
|
-
import type { TLSSocketOptions, ConnectionOptions as TLSConnectionOptions } from 'tls';
|
|
34
|
-
import type { TcpNetConnectOpts } from 'net';
|
|
35
|
-
import type { SrvPoller } from './sdam/srv_polling';
|
|
36
|
-
import type { Connection } from './cmap/connection';
|
|
37
|
-
import type { LEGAL_TLS_SOCKET_OPTIONS, LEGAL_TCP_SOCKET_OPTIONS } from './cmap/connect';
|
|
38
|
-
import type { Encrypter } from './encrypter';
|
|
39
|
-
import { TypedEventEmitter } from './mongo_types';
|
|
41
|
+
import type { W, WriteConcern } from './write_concern';
|
|
40
42
|
|
|
41
43
|
/** @public */
|
|
42
44
|
export const ServerApiVersion = Object.freeze({
|
|
@@ -246,6 +248,14 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
|
|
|
246
248
|
autoEncryption?: AutoEncryptionOptions;
|
|
247
249
|
/** Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver */
|
|
248
250
|
driverInfo?: DriverInfo;
|
|
251
|
+
/** Configures a Socks5 proxy host used for creating TCP connections. */
|
|
252
|
+
proxyHost?: string;
|
|
253
|
+
/** Configures a Socks5 proxy port used for creating TCP connections. */
|
|
254
|
+
proxyPort?: number;
|
|
255
|
+
/** Configures a Socks5 proxy username when the proxy in proxyHost requires username/password authentication. */
|
|
256
|
+
proxyUsername?: string;
|
|
257
|
+
/** Configures a Socks5 proxy password when the proxy in proxyHost requires username/password authentication. */
|
|
258
|
+
proxyPassword?: string;
|
|
249
259
|
|
|
250
260
|
/** @internal */
|
|
251
261
|
srvPoller?: SrvPoller;
|
|
@@ -411,9 +421,9 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
411
421
|
*
|
|
412
422
|
* @see docs.mongodb.org/manual/reference/connection-string/
|
|
413
423
|
*/
|
|
414
|
-
connect(): Promise<
|
|
415
|
-
connect(callback: Callback<
|
|
416
|
-
connect(callback?: Callback<
|
|
424
|
+
connect(): Promise<this>;
|
|
425
|
+
connect(callback: Callback<this>): void;
|
|
426
|
+
connect(callback?: Callback<this>): Promise<this> | void {
|
|
417
427
|
if (callback && typeof callback !== 'function') {
|
|
418
428
|
throw new MongoInvalidArgumentError('Method `connect` only accepts a callback');
|
|
419
429
|
}
|
|
@@ -675,6 +685,10 @@ export interface MongoOptions
|
|
|
675
685
|
dbName: string;
|
|
676
686
|
metadata: ClientMetadata;
|
|
677
687
|
autoEncrypter?: AutoEncrypter;
|
|
688
|
+
proxyHost?: string;
|
|
689
|
+
proxyPort?: number;
|
|
690
|
+
proxyUsername?: string;
|
|
691
|
+
proxyPassword?: string;
|
|
678
692
|
/** @internal */
|
|
679
693
|
connectionType?: typeof Connection;
|
|
680
694
|
|
package/src/mongo_types.ts
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
+
import type { ObjectIdLike } from 'bson';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
|
|
1
4
|
import type {
|
|
2
5
|
Binary,
|
|
3
|
-
Document,
|
|
4
|
-
ObjectId,
|
|
5
6
|
BSONRegExp,
|
|
6
|
-
Timestamp,
|
|
7
7
|
Decimal128,
|
|
8
|
+
Document,
|
|
8
9
|
Double,
|
|
9
10
|
Int32,
|
|
10
|
-
Long
|
|
11
|
+
Long,
|
|
12
|
+
ObjectId,
|
|
13
|
+
Timestamp
|
|
11
14
|
} from './bson';
|
|
12
|
-
import { EventEmitter } from 'events';
|
|
13
15
|
import type { Sort } from './sort';
|
|
14
16
|
|
|
15
17
|
/** @internal */
|
|
16
18
|
export type TODO_NODE_3286 = any;
|
|
17
19
|
|
|
18
20
|
/** Given an object shaped type, return the type of the _id field or default to ObjectId @public */
|
|
19
|
-
export type InferIdType<TSchema> = TSchema extends { _id: infer IdType }
|
|
20
|
-
? //
|
|
21
|
-
|
|
22
|
-
? //
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
export type InferIdType<TSchema> = TSchema extends { _id: infer IdType }
|
|
22
|
+
? // user has defined a type for _id
|
|
23
|
+
Record<any, never> extends IdType
|
|
24
|
+
? never // explicitly forbid empty objects as the type of _id
|
|
25
|
+
: IdType
|
|
26
|
+
: TSchema extends { _id?: infer IdType }
|
|
27
|
+
? // optional _id defined - return ObjectId | IdType
|
|
28
|
+
unknown extends IdType
|
|
29
|
+
? ObjectId // infer the _id type as ObjectId if the type of _id is unknown
|
|
26
30
|
: IdType
|
|
27
31
|
: ObjectId; // user has not defined _id on schema
|
|
28
32
|
|
|
@@ -32,17 +36,23 @@ export type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & { _id: InferIdType<
|
|
|
32
36
|
/**
|
|
33
37
|
* Add an optional _id field to an object shaped type
|
|
34
38
|
* @public
|
|
39
|
+
*/
|
|
40
|
+
export type OptionalId<TSchema> = EnhancedOmit<TSchema, '_id'> & { _id?: InferIdType<TSchema> };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Adds an optional _id field to an object shaped type, unless the _id field is requried on that type.
|
|
44
|
+
* In the case _id is required, this method continues to require_id.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
35
47
|
*
|
|
36
48
|
* @privateRemarks
|
|
37
49
|
* `ObjectId extends TSchema['_id']` is a confusing ordering at first glance. Rather than ask
|
|
38
50
|
* `TSchema['_id'] extends ObjectId` which translated to "Is the _id property ObjectId?"
|
|
39
51
|
* we instead ask "Does ObjectId look like (have the same shape) as the _id?"
|
|
40
52
|
*/
|
|
41
|
-
export type
|
|
42
|
-
?
|
|
43
|
-
|
|
44
|
-
: WithId<TSchema>
|
|
45
|
-
: EnhancedOmit<TSchema, '_id'> & { _id?: InferIdType<TSchema> }; // TODO(NODE-3285): Improve type readability
|
|
53
|
+
export type OptionalUnlessRequiredId<TSchema> = TSchema extends { _id: any }
|
|
54
|
+
? TSchema
|
|
55
|
+
: OptionalId<TSchema>;
|
|
46
56
|
|
|
47
57
|
/** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
|
|
48
58
|
export type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion
|
|
@@ -55,9 +65,13 @@ export type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecor
|
|
|
55
65
|
export type WithoutId<TSchema> = Omit<TSchema, '_id'>;
|
|
56
66
|
|
|
57
67
|
/** A MongoDB filter can be some portion of the schema or a set of operators @public */
|
|
58
|
-
export type Filter<TSchema> =
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
export type Filter<TSchema> =
|
|
69
|
+
| Partial<TSchema>
|
|
70
|
+
| ({
|
|
71
|
+
[Property in Join<NestedPaths<WithId<TSchema>>, '.'>]?: Condition<
|
|
72
|
+
PropertyType<WithId<TSchema>, Property>
|
|
73
|
+
>;
|
|
74
|
+
} & RootFilterOperators<WithId<TSchema>>);
|
|
61
75
|
|
|
62
76
|
/** @public */
|
|
63
77
|
export type Condition<T> = AlternativeType<T> | FilterOperators<AlternativeType<T>>;
|
|
@@ -90,8 +104,16 @@ export interface RootFilterOperators<TSchema> extends Document {
|
|
|
90
104
|
$comment?: string | Document;
|
|
91
105
|
}
|
|
92
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @public
|
|
109
|
+
* A type that extends Document but forbids anything that "looks like" an object id.
|
|
110
|
+
*/
|
|
111
|
+
export type NonObjectIdLikeDocument = {
|
|
112
|
+
[key in keyof ObjectIdLike]?: never;
|
|
113
|
+
} & Document;
|
|
114
|
+
|
|
93
115
|
/** @public */
|
|
94
|
-
export interface FilterOperators<TValue> extends
|
|
116
|
+
export interface FilterOperators<TValue> extends NonObjectIdLikeDocument {
|
|
95
117
|
// Comparison
|
|
96
118
|
$eq?: TValue;
|
|
97
119
|
$gt?: TValue;
|
|
@@ -422,3 +444,79 @@ export class TypedEventEmitter<Events extends EventsDescription> extends EventEm
|
|
|
422
444
|
|
|
423
445
|
/** @public */
|
|
424
446
|
export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Helper types for dot-notation filter attributes
|
|
450
|
+
*/
|
|
451
|
+
|
|
452
|
+
/** @public */
|
|
453
|
+
export type Join<T extends unknown[], D extends string> = T extends []
|
|
454
|
+
? ''
|
|
455
|
+
: T extends [string | number]
|
|
456
|
+
? `${T[0]}`
|
|
457
|
+
: T extends [string | number, ...infer R]
|
|
458
|
+
? `${T[0]}${D}${Join<R, D>}`
|
|
459
|
+
: string;
|
|
460
|
+
|
|
461
|
+
/** @public */
|
|
462
|
+
export type PropertyType<Type, Property extends string> = string extends Property
|
|
463
|
+
? unknown
|
|
464
|
+
: Property extends keyof Type
|
|
465
|
+
? Type[Property]
|
|
466
|
+
: Property extends `${number}`
|
|
467
|
+
? Type extends ReadonlyArray<infer ArrayType>
|
|
468
|
+
? ArrayType
|
|
469
|
+
: unknown
|
|
470
|
+
: Property extends `${infer Key}.${infer Rest}`
|
|
471
|
+
? Key extends `${number}`
|
|
472
|
+
? Type extends ReadonlyArray<infer ArrayType>
|
|
473
|
+
? PropertyType<ArrayType, Rest>
|
|
474
|
+
: unknown
|
|
475
|
+
: Key extends keyof Type
|
|
476
|
+
? Type[Key] extends Map<string, infer MapType>
|
|
477
|
+
? MapType
|
|
478
|
+
: PropertyType<Type[Key], Rest>
|
|
479
|
+
: unknown
|
|
480
|
+
: unknown;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* @public
|
|
484
|
+
* returns tuple of strings (keys to be joined on '.') that represent every path into a schema
|
|
485
|
+
* https://docs.mongodb.com/manual/tutorial/query-embedded-documents/
|
|
486
|
+
*/
|
|
487
|
+
export type NestedPaths<Type> = Type extends
|
|
488
|
+
| string
|
|
489
|
+
| number
|
|
490
|
+
| boolean
|
|
491
|
+
| Date
|
|
492
|
+
| RegExp
|
|
493
|
+
| Buffer
|
|
494
|
+
| Uint8Array
|
|
495
|
+
| ((...args: any[]) => any)
|
|
496
|
+
| { _bsontype: string }
|
|
497
|
+
? []
|
|
498
|
+
: Type extends ReadonlyArray<infer ArrayType>
|
|
499
|
+
? [number, ...NestedPaths<ArrayType>]
|
|
500
|
+
: Type extends Map<string, any>
|
|
501
|
+
? [string]
|
|
502
|
+
: // eslint-disable-next-line @typescript-eslint/ban-types
|
|
503
|
+
Type extends object
|
|
504
|
+
? {
|
|
505
|
+
[Key in Extract<keyof Type, string>]: Type[Key] extends Type // type of value extends the parent
|
|
506
|
+
? [Key]
|
|
507
|
+
: // for a recursive union type, the child will never extend the parent type.
|
|
508
|
+
// but the parent will still extend the child
|
|
509
|
+
Type extends Type[Key]
|
|
510
|
+
? [Key]
|
|
511
|
+
: Type[Key] extends ReadonlyArray<infer ArrayType> // handling recursive types with arrays
|
|
512
|
+
? Type extends ArrayType // is the type of the parent the same as the type of the array?
|
|
513
|
+
? [Key] // yes, it's a recursive array type
|
|
514
|
+
: // for unions, the child type extends the parent
|
|
515
|
+
ArrayType extends Type
|
|
516
|
+
? [Key] // we have a recursive array union
|
|
517
|
+
: // child is an array, but it's not a recursive array
|
|
518
|
+
[Key, ...NestedPaths<Type[Key]>]
|
|
519
|
+
: // child is not structured the same as the parent
|
|
520
|
+
[Key, ...NestedPaths<Type[Key]>];
|
|
521
|
+
}[Extract<keyof Type, string>]
|
|
522
|
+
: [];
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as crypto from 'crypto';
|
|
2
|
-
|
|
3
|
-
import { CommandOperation, CommandOperationOptions } from './command';
|
|
4
|
-
import { MongoInvalidArgumentError } from '../error';
|
|
5
|
-
import { Callback, emitWarningOnce, getTopology } from '../utils';
|
|
2
|
+
|
|
6
3
|
import type { Document } from '../bson';
|
|
7
|
-
import type { Server } from '../sdam/server';
|
|
8
4
|
import type { Db } from '../db';
|
|
5
|
+
import { MongoInvalidArgumentError } from '../error';
|
|
6
|
+
import type { Server } from '../sdam/server';
|
|
9
7
|
import type { ClientSession } from '../sessions';
|
|
8
|
+
import { Callback, emitWarningOnce, getTopology } from '../utils';
|
|
9
|
+
import { CommandOperation, CommandOperationOptions } from './command';
|
|
10
|
+
import { Aspect, defineAspects } from './operation';
|
|
10
11
|
|
|
11
12
|
/** @public */
|
|
12
13
|
export interface RoleSpecification {
|
|
@@ -74,7 +75,7 @@ export class AddUserOperation extends CommandOperation<Document> {
|
|
|
74
75
|
roles = Array.isArray(options.roles) ? options.roles : [options.roles];
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
const digestPassword = getTopology(db).
|
|
78
|
+
const digestPassword = getTopology(db).lastHello().maxWireVersion >= 7;
|
|
78
79
|
|
|
79
80
|
let userPassword = password;
|
|
80
81
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CommandOperation, CommandOperationOptions, CollationOptions } from './command';
|
|
2
|
-
import { MongoInvalidArgumentError } from '../error';
|
|
3
|
-
import { maxWireVersion, MongoDBNamespace } from '../utils';
|
|
4
|
-
import { Aspect, defineAspects, Hint } from './operation';
|
|
5
|
-
import type { Callback } from '../utils';
|
|
6
1
|
import type { Document } from '../bson';
|
|
2
|
+
import { MongoInvalidArgumentError } from '../error';
|
|
7
3
|
import type { Server } from '../sdam/server';
|
|
8
4
|
import type { ClientSession } from '../sessions';
|
|
5
|
+
import type { Callback } from '../utils';
|
|
6
|
+
import { maxWireVersion, MongoDBNamespace } from '../utils';
|
|
7
|
+
import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
|
|
8
|
+
import { Aspect, defineAspects, Hint } from './operation';
|
|
9
9
|
|
|
10
10
|
/** @internal */
|
|
11
11
|
export const DB_AGGREGATE_COLLECTION = 1 as const;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Aspect, defineAspects, AbstractOperation } from './operation';
|
|
2
|
-
import type { Callback } from '../utils';
|
|
3
|
-
import type { Collection } from '../collection';
|
|
4
1
|
import type {
|
|
2
|
+
AnyBulkWriteOperation,
|
|
5
3
|
BulkOperationBase,
|
|
6
|
-
BulkWriteResult,
|
|
7
4
|
BulkWriteOptions,
|
|
8
|
-
|
|
5
|
+
BulkWriteResult
|
|
9
6
|
} from '../bulk/common';
|
|
7
|
+
import type { Collection } from '../collection';
|
|
10
8
|
import type { Server } from '../sdam/server';
|
|
11
9
|
import type { ClientSession } from '../sessions';
|
|
10
|
+
import type { Callback } from '../utils';
|
|
11
|
+
import { AbstractOperation, Aspect, defineAspects } from './operation';
|
|
12
12
|
|
|
13
13
|
/** @internal */
|
|
14
14
|
export class BulkWriteOperation extends AbstractOperation<BulkWriteResult> {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AbstractOperation, OperationOptions } from './operation';
|
|
2
1
|
import { Collection } from '../collection';
|
|
3
|
-
import type { Callback } from '../utils';
|
|
4
2
|
import type { Db } from '../db';
|
|
5
3
|
import type { Server } from '../sdam/server';
|
|
6
4
|
import type { ClientSession } from '../sessions';
|
|
5
|
+
import type { Callback } from '../utils';
|
|
6
|
+
import { AbstractOperation, OperationOptions } from './operation';
|
|
7
7
|
|
|
8
8
|
export interface CollectionsOptions extends OperationOptions {
|
|
9
9
|
nameOnly?: boolean;
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BSONSerializeOptions, Document } from '../bson';
|
|
2
|
+
import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
|
|
3
|
+
import { Explain, ExplainOptions } from '../explain';
|
|
4
|
+
import type { Logger } from '../logger';
|
|
2
5
|
import { ReadConcern } from '../read_concern';
|
|
3
|
-
import { WriteConcern, WriteConcernOptions } from '../write_concern';
|
|
4
|
-
import { maxWireVersion, MongoDBNamespace, Callback, decorateWithExplain } from '../utils';
|
|
5
6
|
import type { ReadPreference } from '../read_preference';
|
|
6
|
-
import { ClientSession, commandSupportsReadConcern } from '../sessions';
|
|
7
|
-
import { MongoInvalidArgumentError, MongoCompatibilityError } from '../error';
|
|
8
|
-
import type { Logger } from '../logger';
|
|
9
7
|
import type { Server } from '../sdam/server';
|
|
10
|
-
import type { BSONSerializeOptions, Document } from '../bson';
|
|
11
|
-
import type { ReadConcernLike } from './../read_concern';
|
|
12
|
-
import { Explain, ExplainOptions } from '../explain';
|
|
13
8
|
import { MIN_SECONDARY_WRITE_WIRE_VERSION } from '../sdam/server_selection';
|
|
9
|
+
import type { ClientSession } from '../sessions';
|
|
10
|
+
import {
|
|
11
|
+
Callback,
|
|
12
|
+
commandSupportsReadConcern,
|
|
13
|
+
decorateWithExplain,
|
|
14
|
+
maxWireVersion,
|
|
15
|
+
MongoDBNamespace
|
|
16
|
+
} from '../utils';
|
|
17
|
+
import { WriteConcern, WriteConcernOptions } from '../write_concern';
|
|
18
|
+
import type { ReadConcernLike } from './../read_concern';
|
|
19
|
+
import { AbstractOperation, Aspect, OperationOptions } from './operation';
|
|
14
20
|
|
|
15
21
|
const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
|
|
16
22
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { MongoTopologyClosedError } from '../error';
|
|
2
|
-
import { Callback, getTopology } from '../utils';
|
|
3
1
|
import type { Document } from '../bson';
|
|
2
|
+
import type { Collection } from '../collection';
|
|
4
3
|
import type { Db } from '../db';
|
|
5
|
-
import
|
|
4
|
+
import { MongoTopologyClosedError } from '../error';
|
|
6
5
|
import type { ReadPreference } from '../read_preference';
|
|
7
|
-
import type {
|
|
6
|
+
import type { ClientSession } from '../sessions';
|
|
7
|
+
import { Callback, getTopology } from '../utils';
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
10
10
|
export interface IndexInformationOptions {
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import { MongoRuntimeError, MongoInvalidArgumentError } from '../error';
|
|
2
|
-
import { Topology, TOPOLOGY_EVENTS } from '../sdam/topology';
|
|
3
1
|
import { resolveSRVRecord } from '../connection_string';
|
|
4
|
-
import
|
|
2
|
+
import { MONGO_CLIENT_EVENTS } from '../constants';
|
|
3
|
+
import { MongoInvalidArgumentError, MongoRuntimeError } from '../error';
|
|
5
4
|
import type { MongoClient, MongoOptions } from '../mongo_client';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { HEARTBEAT_EVENTS } from '../sdam/server';
|
|
9
|
-
|
|
10
|
-
/** @public */
|
|
11
|
-
export const MONGO_CLIENT_EVENTS = [
|
|
12
|
-
...CMAP_EVENTS,
|
|
13
|
-
...APM_EVENTS,
|
|
14
|
-
...TOPOLOGY_EVENTS,
|
|
15
|
-
...HEARTBEAT_EVENTS
|
|
16
|
-
] as const;
|
|
5
|
+
import { Topology } from '../sdam/topology';
|
|
6
|
+
import type { Callback } from '../utils';
|
|
17
7
|
|
|
18
8
|
export function connect(
|
|
19
9
|
mongoClient: MongoClient,
|
package/src/operations/count.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Aspect, defineAspects } from './operation';
|
|
2
|
-
import { CommandOperation, CommandOperationOptions } from './command';
|
|
3
|
-
import type { Callback, MongoDBNamespace } from '../utils';
|
|
4
1
|
import type { Document } from '../bson';
|
|
5
|
-
import type { Server } from '../sdam/server';
|
|
6
2
|
import type { Collection } from '../collection';
|
|
3
|
+
import type { Server } from '../sdam/server';
|
|
7
4
|
import type { ClientSession } from '../sessions';
|
|
5
|
+
import type { Callback, MongoDBNamespace } from '../utils';
|
|
6
|
+
import { CommandOperation, CommandOperationOptions } from './command';
|
|
7
|
+
import { Aspect, defineAspects } from './operation';
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
10
10
|
export interface CountOptions extends CommandOperationOptions {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AggregateOperation, AggregateOptions } from './aggregate';
|
|
2
|
-
import type { Callback } from '../utils';
|
|
3
1
|
import type { Document } from '../bson';
|
|
4
|
-
import type { Server } from '../sdam/server';
|
|
5
2
|
import type { Collection } from '../collection';
|
|
3
|
+
import type { Server } from '../sdam/server';
|
|
6
4
|
import type { ClientSession } from '../sessions';
|
|
5
|
+
import type { Callback } from '../utils';
|
|
6
|
+
import { AggregateOperation, AggregateOptions } from './aggregate';
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
9
9
|
export interface CountDocumentsOptions extends AggregateOptions {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { CommandOperation, CommandOperationOptions } from './command';
|
|
2
|
-
import { Aspect, defineAspects } from './operation';
|
|
3
|
-
import { Collection } from '../collection';
|
|
4
|
-
import type { Callback } from '../utils';
|
|
5
1
|
import type { Document } from '../bson';
|
|
6
|
-
import
|
|
2
|
+
import { Collection } from '../collection';
|
|
7
3
|
import type { Db } from '../db';
|
|
8
4
|
import type { PkFactory } from '../mongo_client';
|
|
5
|
+
import type { Server } from '../sdam/server';
|
|
9
6
|
import type { ClientSession } from '../sessions';
|
|
7
|
+
import type { Callback } from '../utils';
|
|
8
|
+
import { CommandOperation, CommandOperationOptions } from './command';
|
|
9
|
+
import { Aspect, defineAspects } from './operation';
|
|
10
10
|
|
|
11
11
|
const ILLEGAL_COMMAND_FIELDS = new Set([
|
|
12
12
|
'w',
|
|
@@ -27,7 +27,8 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
|
|
|
27
27
|
'promoteBuffers',
|
|
28
28
|
'bsonRegExp',
|
|
29
29
|
'serializeFunctions',
|
|
30
|
-
'ignoreUndefined'
|
|
30
|
+
'ignoreUndefined',
|
|
31
|
+
'enableUtf8Validation'
|
|
31
32
|
]);
|
|
32
33
|
|
|
33
34
|
/** @public
|
package/src/operations/delete.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { defineAspects, Aspect, Hint } from './operation';
|
|
2
|
-
import { CommandOperation, CommandOperationOptions, CollationOptions } from './command';
|
|
3
|
-
import { Callback, maxWireVersion, MongoDBNamespace, collationNotSupported } from '../utils';
|
|
4
1
|
import type { Document } from '../bson';
|
|
5
|
-
import type { Server } from '../sdam/server';
|
|
6
2
|
import type { Collection } from '../collection';
|
|
3
|
+
import { MongoCompatibilityError, MongoServerError } from '../error';
|
|
4
|
+
import type { Server } from '../sdam/server';
|
|
7
5
|
import type { ClientSession } from '../sessions';
|
|
8
|
-
import {
|
|
6
|
+
import { Callback, collationNotSupported, maxWireVersion, MongoDBNamespace } from '../utils';
|
|
9
7
|
import type { WriteConcernOptions } from '../write_concern';
|
|
8
|
+
import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
|
|
9
|
+
import { Aspect, defineAspects, Hint } from './operation';
|
|
10
10
|
|
|
11
11
|
/** @public */
|
|
12
12
|
export interface DeleteOptions extends CommandOperationOptions, WriteConcernOptions {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Aspect, defineAspects } from './operation';
|
|
2
|
-
import { CommandOperation, CommandOperationOptions } from './command';
|
|
3
|
-
import { decorateWithCollation, decorateWithReadConcern, Callback, maxWireVersion } from '../utils';
|
|
4
1
|
import type { Document } from '../bson';
|
|
5
|
-
import type { Server } from '../sdam/server';
|
|
6
2
|
import type { Collection } from '../collection';
|
|
7
3
|
import { MongoCompatibilityError } from '../error';
|
|
4
|
+
import type { Server } from '../sdam/server';
|
|
8
5
|
import type { ClientSession } from '../sessions';
|
|
6
|
+
import { Callback, decorateWithCollation, decorateWithReadConcern, maxWireVersion } from '../utils';
|
|
7
|
+
import { CommandOperation, CommandOperationOptions } from './command';
|
|
8
|
+
import { Aspect, defineAspects } from './operation';
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
11
|
export type DistinctOptions = CommandOperationOptions;
|
package/src/operations/drop.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Aspect, defineAspects } from './operation';
|
|
2
|
-
import { CommandOperation, CommandOperationOptions } from './command';
|
|
3
|
-
import type { Callback } from '../utils';
|
|
4
|
-
import type { Server } from '../sdam/server';
|
|
5
1
|
import type { Db } from '../db';
|
|
2
|
+
import type { Server } from '../sdam/server';
|
|
6
3
|
import type { ClientSession } from '../sessions';
|
|
4
|
+
import type { Callback } from '../utils';
|
|
5
|
+
import { CommandOperation, CommandOperationOptions } from './command';
|
|
6
|
+
import { Aspect, defineAspects } from './operation';
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
9
9
|
export type DropCollectionOptions = CommandOperationOptions;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Aspect, defineAspects } from './operation';
|
|
2
|
-
import { CommandOperation, CommandOperationOptions } from './command';
|
|
3
|
-
import { Callback, maxWireVersion } from '../utils';
|
|
4
1
|
import type { Document } from '../bson';
|
|
5
|
-
import type { Server } from '../sdam/server';
|
|
6
2
|
import type { Collection } from '../collection';
|
|
7
|
-
import type { ClientSession } from '../sessions';
|
|
8
3
|
import type { MongoServerError } from '../error';
|
|
4
|
+
import type { Server } from '../sdam/server';
|
|
5
|
+
import type { ClientSession } from '../sessions';
|
|
6
|
+
import { Callback, maxWireVersion } from '../utils';
|
|
7
|
+
import { CommandOperation, CommandOperationOptions } from './command';
|
|
8
|
+
import { Aspect, defineAspects } from './operation';
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
11
|
export interface EstimatedDocumentCountOptions extends CommandOperationOptions {
|
package/src/operations/eval.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { CommandOperation, CommandOperationOptions } from './command';
|
|
2
1
|
import { Code, Document } from '../bson';
|
|
3
|
-
import {
|
|
2
|
+
import type { Collection } from '../collection';
|
|
3
|
+
import type { Db } from '../db';
|
|
4
4
|
import { MongoServerError } from '../error';
|
|
5
|
-
import
|
|
5
|
+
import { ReadPreference } from '../read_preference';
|
|
6
6
|
import type { Server } from '../sdam/server';
|
|
7
|
-
import type { Db } from '../db';
|
|
8
|
-
import type { Collection } from '../collection';
|
|
9
7
|
import type { ClientSession } from '../sessions';
|
|
8
|
+
import type { Callback } from '../utils';
|
|
9
|
+
import { CommandOperation, CommandOperationOptions } from './command';
|
|
10
10
|
|
|
11
11
|
/** @public */
|
|
12
12
|
export interface EvalOptions extends CommandOperationOptions {
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
2
|
import {
|
|
3
|
-
MongoError,
|
|
4
3
|
isRetryableError,
|
|
4
|
+
MongoCompatibilityError,
|
|
5
5
|
MONGODB_ERROR_CODES,
|
|
6
|
-
|
|
6
|
+
MongoError,
|
|
7
|
+
MongoExpiredSessionError,
|
|
7
8
|
MongoNetworkError,
|
|
8
|
-
|
|
9
|
+
MongoRuntimeError,
|
|
9
10
|
MongoServerError,
|
|
10
|
-
MongoExpiredSessionError,
|
|
11
11
|
MongoTransactionError
|
|
12
12
|
} from '../error';
|
|
13
|
-
import {
|
|
14
|
-
import { maxWireVersion, maybePromise, Callback } from '../utils';
|
|
13
|
+
import { ReadPreference } from '../read_preference';
|
|
15
14
|
import type { Server } from '../sdam/server';
|
|
15
|
+
import {
|
|
16
|
+
sameServerSelector,
|
|
17
|
+
secondaryWritableServerSelector,
|
|
18
|
+
ServerSelector
|
|
19
|
+
} from '../sdam/server_selection';
|
|
16
20
|
import type { Topology } from '../sdam/topology';
|
|
17
21
|
import type { ClientSession } from '../sessions';
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import { secondaryWritableServerSelector, ServerSelector } from '../sdam/server_selection';
|
|
22
|
+
import { Callback, maxWireVersion, maybePromise, supportsRetryableWrites } from '../utils';
|
|
23
|
+
import { AbstractOperation, Aspect } from './operation';
|
|
21
24
|
|
|
22
25
|
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
|
|
23
26
|
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE =
|
|
@@ -153,9 +156,14 @@ function executeWithServerSelection(
|
|
|
153
156
|
|
|
154
157
|
let selector: ReadPreference | ServerSelector;
|
|
155
158
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
if (operation.hasAspect(Aspect.CURSOR_ITERATING)) {
|
|
160
|
+
// Get more operations must always select the same server, but run through
|
|
161
|
+
// server selection to potentially force monitor checks if the server is
|
|
162
|
+
// in an unknown state.
|
|
163
|
+
selector = sameServerSelector(operation.server?.description);
|
|
164
|
+
} else if (operation.trySecondaryWrite) {
|
|
165
|
+
// If operation should try to write to secondary use the custom server selector
|
|
166
|
+
// otherwise provide the read preference.
|
|
159
167
|
selector = secondaryWritableServerSelector(topology.commonWireVersion, readPreference);
|
|
160
168
|
} else {
|
|
161
169
|
selector = readPreference;
|