mongodb 5.0.1 → 5.2.0
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 +25 -22
- package/lib/bson.js +3 -1
- package/lib/bson.js.map +1 -1
- package/lib/change_stream.js +3 -2
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js +21 -10
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +71 -116
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +17 -0
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +20 -29
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +126 -140
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +28 -0
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +178 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +41 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js +115 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js +3 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +62 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
- package/lib/cmap/auth/plain.js +4 -5
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/providers.js +4 -1
- package/lib/cmap/auth/providers.js.map +1 -1
- package/lib/cmap/auth/scram.js +45 -73
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +8 -11
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +8 -5
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +9 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +72 -86
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +68 -74
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +51 -13
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +1 -16
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +10 -10
- package/lib/connection_string.js +47 -33
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +13 -7
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/db.js +3 -2
- package/lib/db.js.map +1 -1
- package/lib/error.js +2 -1
- package/lib/error.js.map +1 -1
- package/lib/mongo_client.js +22 -2
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +17 -1
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/aggregate.js +4 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/create_collection.js +1 -0
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/execute_operation.js +8 -27
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +3 -2
- package/lib/operations/find.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/read_concern.js +1 -1
- package/lib/read_preference.js +2 -2
- package/lib/sdam/monitor.js +1 -0
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +4 -2
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/topology.js +3 -26
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +2 -1
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +15 -70
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js +1 -1
- package/mongodb.d.ts +137 -68
- package/package.json +30 -30
- package/src/bson.ts +3 -1
- package/src/bulk/common.ts +1 -1
- package/src/change_stream.ts +16 -8
- package/src/cmap/auth/auth_provider.ts +29 -16
- package/src/cmap/auth/gssapi.ts +102 -149
- package/src/cmap/auth/mongo_credentials.ts +47 -1
- package/src/cmap/auth/mongocr.ts +31 -36
- package/src/cmap/auth/mongodb_aws.ts +167 -189
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +26 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +259 -0
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +47 -0
- package/src/cmap/auth/mongodb_oidc/token_entry_cache.ts +166 -0
- package/src/cmap/auth/mongodb_oidc/workflow.ts +21 -0
- package/src/cmap/auth/mongodb_oidc.ts +123 -0
- package/src/cmap/auth/plain.ts +6 -6
- package/src/cmap/auth/providers.ts +5 -2
- package/src/cmap/auth/scram.ts +56 -90
- package/src/cmap/auth/x509.ts +12 -18
- package/src/cmap/command_monitoring_events.ts +5 -2
- package/src/cmap/commands.ts +11 -1
- package/src/cmap/connect.ts +90 -114
- package/src/cmap/connection.ts +92 -90
- package/src/cmap/connection_pool.ts +77 -16
- package/src/cmap/message_stream.ts +0 -2
- package/src/cmap/wire_protocol/compression.ts +1 -1
- package/src/cmap/wire_protocol/shared.ts +1 -23
- package/src/collection.ts +11 -11
- package/src/connection_string.ts +52 -35
- package/src/cursor/abstract_cursor.ts +13 -6
- package/src/cursor/change_stream_cursor.ts +5 -5
- package/src/cursor/find_cursor.ts +1 -1
- package/src/db.ts +3 -2
- package/src/deps.ts +56 -38
- package/src/error.ts +3 -2
- package/src/index.ts +7 -0
- package/src/mongo_client.ts +35 -10
- package/src/mongo_logger.ts +20 -2
- package/src/mongo_types.ts +4 -3
- package/src/operations/aggregate.ts +4 -2
- package/src/operations/create_collection.ts +2 -1
- package/src/operations/execute_operation.ts +8 -25
- package/src/operations/find.ts +13 -4
- package/src/operations/find_and_modify.ts +4 -4
- package/src/operations/indexes.ts +12 -4
- package/src/operations/list_collections.ts +11 -3
- package/src/operations/set_profiling_level.ts +1 -1
- package/src/operations/stats.ts +1 -1
- package/src/read_concern.ts +2 -2
- package/src/read_preference.ts +3 -3
- package/src/sdam/common.ts +2 -2
- package/src/sdam/monitor.ts +1 -0
- package/src/sdam/server.ts +4 -1
- package/src/sdam/topology.ts +4 -33
- package/src/sessions.ts +2 -1
- package/src/transactions.ts +1 -1
- package/src/utils.ts +24 -98
- package/src/write_concern.ts +1 -1
|
@@ -16,8 +16,11 @@ import {
|
|
|
16
16
|
CONNECTION_READY
|
|
17
17
|
} from '../constants';
|
|
18
18
|
import {
|
|
19
|
+
AnyError,
|
|
20
|
+
MONGODB_ERROR_CODES,
|
|
19
21
|
MongoError,
|
|
20
22
|
MongoInvalidArgumentError,
|
|
23
|
+
MongoMissingCredentialsError,
|
|
21
24
|
MongoNetworkError,
|
|
22
25
|
MongoRuntimeError,
|
|
23
26
|
MongoServerError
|
|
@@ -25,7 +28,7 @@ import {
|
|
|
25
28
|
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
26
29
|
import type { Server } from '../sdam/server';
|
|
27
30
|
import { Callback, eachAsync, List, makeCounter } from '../utils';
|
|
28
|
-
import { connect } from './connect';
|
|
31
|
+
import { AUTH_PROVIDERS, connect } from './connect';
|
|
29
32
|
import { Connection, ConnectionEvents, ConnectionOptions } from './connection';
|
|
30
33
|
import {
|
|
31
34
|
ConnectionCheckedInEvent,
|
|
@@ -135,7 +138,7 @@ export type ConnectionPoolEvents = {
|
|
|
135
138
|
*/
|
|
136
139
|
export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
137
140
|
options: Readonly<ConnectionPoolOptions>;
|
|
138
|
-
[kPoolState]: typeof PoolState[keyof typeof PoolState];
|
|
141
|
+
[kPoolState]: (typeof PoolState)[keyof typeof PoolState];
|
|
139
142
|
[kServer]: Server;
|
|
140
143
|
[kConnections]: List<Connection>;
|
|
141
144
|
[kPending]: number;
|
|
@@ -510,7 +513,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
510
513
|
ConnectionPool.CONNECTION_CLOSED,
|
|
511
514
|
new ConnectionClosedEvent(this, conn, 'poolClosed')
|
|
512
515
|
);
|
|
513
|
-
conn.destroy(options, cb);
|
|
516
|
+
conn.destroy({ force: !!options.force }, cb);
|
|
514
517
|
},
|
|
515
518
|
err => {
|
|
516
519
|
this[kConnections].clear();
|
|
@@ -537,32 +540,30 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
537
540
|
withConnection(
|
|
538
541
|
conn: Connection | undefined,
|
|
539
542
|
fn: WithConnectionCallback,
|
|
540
|
-
callback
|
|
543
|
+
callback: Callback<Connection>
|
|
541
544
|
): void {
|
|
542
545
|
if (conn) {
|
|
543
546
|
// use the provided connection, and do _not_ check it in after execution
|
|
544
547
|
fn(undefined, conn, (fnErr, result) => {
|
|
545
|
-
if (
|
|
546
|
-
|
|
547
|
-
callback(fnErr);
|
|
548
|
-
} else {
|
|
549
|
-
callback(undefined, result);
|
|
550
|
-
}
|
|
548
|
+
if (fnErr) {
|
|
549
|
+
return this.withReauthentication(fnErr, conn, fn, callback);
|
|
551
550
|
}
|
|
551
|
+
callback(undefined, result);
|
|
552
552
|
});
|
|
553
|
-
|
|
554
553
|
return;
|
|
555
554
|
}
|
|
556
555
|
|
|
557
556
|
this.checkOut((err, conn) => {
|
|
558
557
|
// don't callback with `err` here, we might want to act upon it inside `fn`
|
|
559
558
|
fn(err as MongoError, conn, (fnErr, result) => {
|
|
560
|
-
if (
|
|
561
|
-
if (
|
|
562
|
-
|
|
559
|
+
if (fnErr) {
|
|
560
|
+
if (conn) {
|
|
561
|
+
this.withReauthentication(fnErr, conn, fn, callback);
|
|
563
562
|
} else {
|
|
564
|
-
callback(
|
|
563
|
+
callback(fnErr);
|
|
565
564
|
}
|
|
565
|
+
} else {
|
|
566
|
+
callback(undefined, result);
|
|
566
567
|
}
|
|
567
568
|
|
|
568
569
|
if (conn) {
|
|
@@ -572,6 +573,66 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
572
573
|
});
|
|
573
574
|
}
|
|
574
575
|
|
|
576
|
+
private withReauthentication(
|
|
577
|
+
fnErr: AnyError,
|
|
578
|
+
conn: Connection,
|
|
579
|
+
fn: WithConnectionCallback,
|
|
580
|
+
callback: Callback<Connection>
|
|
581
|
+
) {
|
|
582
|
+
if (fnErr instanceof MongoError && fnErr.code === MONGODB_ERROR_CODES.Reauthenticate) {
|
|
583
|
+
this.reauthenticate(conn, fn, (error, res) => {
|
|
584
|
+
if (error) {
|
|
585
|
+
return callback(error);
|
|
586
|
+
}
|
|
587
|
+
callback(undefined, res);
|
|
588
|
+
});
|
|
589
|
+
} else {
|
|
590
|
+
callback(fnErr);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Reauthenticate on the same connection and then retry the operation.
|
|
596
|
+
*/
|
|
597
|
+
private reauthenticate(
|
|
598
|
+
connection: Connection,
|
|
599
|
+
fn: WithConnectionCallback,
|
|
600
|
+
callback: Callback
|
|
601
|
+
): void {
|
|
602
|
+
const authContext = connection.authContext;
|
|
603
|
+
if (!authContext) {
|
|
604
|
+
return callback(new MongoRuntimeError('No auth context found on connection.'));
|
|
605
|
+
}
|
|
606
|
+
const credentials = authContext.credentials;
|
|
607
|
+
if (!credentials) {
|
|
608
|
+
return callback(
|
|
609
|
+
new MongoMissingCredentialsError(
|
|
610
|
+
'Connection is missing credentials when asked to reauthenticate'
|
|
611
|
+
)
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
const resolvedCredentials = credentials.resolveAuthMechanism(connection.hello || undefined);
|
|
615
|
+
const provider = AUTH_PROVIDERS.get(resolvedCredentials.mechanism);
|
|
616
|
+
if (!provider) {
|
|
617
|
+
return callback(
|
|
618
|
+
new MongoMissingCredentialsError(
|
|
619
|
+
`Reauthenticate failed due to no auth provider for ${credentials.mechanism}`
|
|
620
|
+
)
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
provider.reauth(authContext).then(
|
|
624
|
+
() => {
|
|
625
|
+
fn(undefined, connection, (fnErr, fnResult) => {
|
|
626
|
+
if (fnErr) {
|
|
627
|
+
return callback(fnErr);
|
|
628
|
+
}
|
|
629
|
+
callback(undefined, fnResult);
|
|
630
|
+
});
|
|
631
|
+
},
|
|
632
|
+
error => callback(error)
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
|
|
575
636
|
/** Clear the min pool size timer */
|
|
576
637
|
private clearMinPoolSizeTimer(): void {
|
|
577
638
|
const minPoolSizeTimer = this[kMinPoolSizeTimer];
|
|
@@ -586,7 +647,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
586
647
|
new ConnectionClosedEvent(this, connection, reason)
|
|
587
648
|
);
|
|
588
649
|
// destroy the connection
|
|
589
|
-
process.nextTick(() => connection.destroy());
|
|
650
|
+
process.nextTick(() => connection.destroy({ force: false }));
|
|
590
651
|
}
|
|
591
652
|
|
|
592
653
|
private connectionIsStale(connection: Connection) {
|
|
@@ -30,13 +30,11 @@ export interface MessageStreamOptions extends DuplexOptions {
|
|
|
30
30
|
export interface OperationDescription extends BSONSerializeOptions {
|
|
31
31
|
started: number;
|
|
32
32
|
cb: Callback<Document>;
|
|
33
|
-
command: boolean;
|
|
34
33
|
documentsReturnedIn?: string;
|
|
35
34
|
noResponse: boolean;
|
|
36
35
|
raw: boolean;
|
|
37
36
|
requestId: number;
|
|
38
37
|
session?: ClientSession;
|
|
39
|
-
socketTimeoutOverride?: boolean;
|
|
40
38
|
agreedCompressor?: CompressorName;
|
|
41
39
|
zlibCompressionLevel?: number;
|
|
42
40
|
$clusterTime?: Document;
|
|
@@ -14,7 +14,7 @@ export const Compressor = Object.freeze({
|
|
|
14
14
|
} as const);
|
|
15
15
|
|
|
16
16
|
/** @public */
|
|
17
|
-
export type Compressor = typeof Compressor[CompressorName];
|
|
17
|
+
export type Compressor = (typeof Compressor)[CompressorName];
|
|
18
18
|
|
|
19
19
|
/** @public */
|
|
20
20
|
export type CompressorName = keyof typeof Compressor;
|
|
@@ -7,8 +7,7 @@ import type { Server } from '../../sdam/server';
|
|
|
7
7
|
import type { ServerDescription } from '../../sdam/server_description';
|
|
8
8
|
import type { Topology } from '../../sdam/topology';
|
|
9
9
|
import { TopologyDescription } from '../../sdam/topology_description';
|
|
10
|
-
import type {
|
|
11
|
-
import type { CommandOptions, Connection } from '../connection';
|
|
10
|
+
import type { Connection } from '../connection';
|
|
12
11
|
|
|
13
12
|
export interface ReadPreferenceOption {
|
|
14
13
|
readPreference?: ReadPreferenceLike;
|
|
@@ -35,27 +34,6 @@ export function getReadPreference(cmd: Document, options?: ReadPreferenceOption)
|
|
|
35
34
|
return readPreference;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
export function applyCommonQueryOptions(
|
|
39
|
-
queryOptions: OpQueryOptions,
|
|
40
|
-
options: CommandOptions
|
|
41
|
-
): CommandOptions {
|
|
42
|
-
Object.assign(queryOptions, {
|
|
43
|
-
raw: typeof options.raw === 'boolean' ? options.raw : false,
|
|
44
|
-
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
|
|
45
|
-
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
|
|
46
|
-
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
|
|
47
|
-
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
|
|
48
|
-
enableUtf8Validation:
|
|
49
|
-
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (options.session) {
|
|
53
|
-
queryOptions.session = options.session;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return queryOptions;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
37
|
export function isSharded(topologyOrServer?: Topology | Server | Connection): boolean {
|
|
60
38
|
if (topologyOrServer == null) {
|
|
61
39
|
return false;
|
package/src/collection.ts
CHANGED
|
@@ -92,7 +92,7 @@ import { WriteConcern, WriteConcernOptions } from './write_concern';
|
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* @public
|
|
95
|
-
* @deprecated This type will be completely removed
|
|
95
|
+
* @deprecated This type will be completely removed and findOneAndUpdate,
|
|
96
96
|
* findOneAndDelete, and findOneAndReplace will then return the
|
|
97
97
|
* actual result document.
|
|
98
98
|
*/
|
|
@@ -568,7 +568,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
568
568
|
* error.
|
|
569
569
|
*
|
|
570
570
|
* **Note**: Unlike {@link Collection#createIndex| createIndex}, this function takes in raw index specifications.
|
|
571
|
-
* Index specifications are defined {@link
|
|
571
|
+
* Index specifications are defined {@link https://www.mongodb.com/docs/manual/reference/command/createIndexes/| here}.
|
|
572
572
|
*
|
|
573
573
|
* @param indexSpecs - An array of index specifications to be created
|
|
574
574
|
* @param options - Optional settings for the command
|
|
@@ -705,18 +705,18 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
705
705
|
* | `$near` | [`$geoWithin`][2] with [`$center`][3] |
|
|
706
706
|
* | `$nearSphere` | [`$geoWithin`][2] with [`$centerSphere`][4] |
|
|
707
707
|
*
|
|
708
|
-
* [1]: https://
|
|
709
|
-
* [2]: https://
|
|
710
|
-
* [3]: https://
|
|
711
|
-
* [4]: https://
|
|
708
|
+
* [1]: https://www.mongodb.com/docs/manual/reference/operator/query/expr/
|
|
709
|
+
* [2]: https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
|
|
710
|
+
* [3]: https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center
|
|
711
|
+
* [4]: https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere
|
|
712
712
|
*
|
|
713
713
|
* @param filter - The filter for the count
|
|
714
714
|
* @param options - Optional settings for the command
|
|
715
715
|
*
|
|
716
|
-
* @see https://
|
|
717
|
-
* @see https://
|
|
718
|
-
* @see https://
|
|
719
|
-
* @see https://
|
|
716
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/expr/
|
|
717
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
|
|
718
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center
|
|
719
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere
|
|
720
720
|
*/
|
|
721
721
|
async countDocuments(
|
|
722
722
|
filter: Document = {},
|
|
@@ -916,7 +916,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
916
916
|
* });
|
|
917
917
|
* ```
|
|
918
918
|
*
|
|
919
|
-
* @param pipeline - An array of {@link https://
|
|
919
|
+
* @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
|
|
920
920
|
* @param options - Optional settings for the command
|
|
921
921
|
* @typeParam TLocal - Type of the data being detected by the change stream
|
|
922
922
|
* @typeParam TChange - Type of the whole change stream document emitted
|
package/src/connection_string.ts
CHANGED
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
MongoParseError
|
|
16
16
|
} from './error';
|
|
17
17
|
import {
|
|
18
|
-
DriverInfo,
|
|
19
18
|
MongoClient,
|
|
20
19
|
MongoClientOptions,
|
|
21
20
|
MongoOptions,
|
|
@@ -255,6 +254,15 @@ export function parseOptions(
|
|
|
255
254
|
mongoClient = undefined;
|
|
256
255
|
}
|
|
257
256
|
|
|
257
|
+
// validate BSONOptions
|
|
258
|
+
if (options.useBigInt64 && typeof options.promoteLongs === 'boolean' && !options.promoteLongs) {
|
|
259
|
+
throw new MongoAPIError('Must request either bigint or Long for int64 deserialization');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (options.useBigInt64 && typeof options.promoteValues === 'boolean' && !options.promoteValues) {
|
|
263
|
+
throw new MongoAPIError('Must request either bigint or Long for int64 deserialization');
|
|
264
|
+
}
|
|
265
|
+
|
|
258
266
|
const url = new ConnectionString(uri);
|
|
259
267
|
const { hosts, isSRV } = url;
|
|
260
268
|
|
|
@@ -386,6 +394,7 @@ export function parseOptions(
|
|
|
386
394
|
const isGssapi = mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_GSSAPI;
|
|
387
395
|
const isX509 = mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_X509;
|
|
388
396
|
const isAws = mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_AWS;
|
|
397
|
+
const isOidc = mongoOptions.credentials.mechanism === AuthMechanism.MONGODB_OIDC;
|
|
389
398
|
if (
|
|
390
399
|
(isGssapi || isX509) &&
|
|
391
400
|
allOptions.has('authSource') &&
|
|
@@ -393,11 +402,15 @@ export function parseOptions(
|
|
|
393
402
|
) {
|
|
394
403
|
// If authSource was explicitly given and its incorrect, we error
|
|
395
404
|
throw new MongoParseError(
|
|
396
|
-
|
|
405
|
+
`authMechanism ${mongoOptions.credentials.mechanism} requires an authSource of '$external'`
|
|
397
406
|
);
|
|
398
407
|
}
|
|
399
408
|
|
|
400
|
-
if (
|
|
409
|
+
if (
|
|
410
|
+
!(isGssapi || isX509 || isAws || isOidc) &&
|
|
411
|
+
mongoOptions.dbName &&
|
|
412
|
+
!allOptions.has('authSource')
|
|
413
|
+
) {
|
|
401
414
|
// inherit the dbName unless GSSAPI or X509, then silently ignore dbName
|
|
402
415
|
// and there was no specific authSource given
|
|
403
416
|
mongoOptions.credentials = MongoCredentials.merge(mongoOptions.credentials, {
|
|
@@ -517,7 +530,8 @@ export function parseOptions(
|
|
|
517
530
|
MONGODB_LOG_CONNECTION: process.env.MONGODB_LOG_CONNECTION,
|
|
518
531
|
MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL,
|
|
519
532
|
MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH,
|
|
520
|
-
MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH
|
|
533
|
+
MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH,
|
|
534
|
+
...mongoOptions[Symbol.for('@@mdb.internalLoggerConfig')]
|
|
521
535
|
};
|
|
522
536
|
loggerClientOptions = {
|
|
523
537
|
mongodbLogPath: mongoOptions.mongodbLogPath
|
|
@@ -528,6 +542,8 @@ export function parseOptions(
|
|
|
528
542
|
loggerClientOptions
|
|
529
543
|
);
|
|
530
544
|
|
|
545
|
+
mongoOptions.metadata = makeClientMetadata(mongoOptions);
|
|
546
|
+
|
|
531
547
|
return mongoOptions;
|
|
532
548
|
}
|
|
533
549
|
|
|
@@ -629,10 +645,7 @@ interface OptionDescriptor {
|
|
|
629
645
|
|
|
630
646
|
export const OPTIONS = {
|
|
631
647
|
appName: {
|
|
632
|
-
|
|
633
|
-
transform({ options, values: [value] }): DriverInfo {
|
|
634
|
-
return makeClientMetadata({ ...options.driverInfo, appName: String(value) });
|
|
635
|
-
}
|
|
648
|
+
type: 'string'
|
|
636
649
|
},
|
|
637
650
|
auth: {
|
|
638
651
|
target: 'credentials',
|
|
@@ -678,26 +691,31 @@ export const OPTIONS = {
|
|
|
678
691
|
},
|
|
679
692
|
authMechanismProperties: {
|
|
680
693
|
target: 'credentials',
|
|
681
|
-
transform({ options, values
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
694
|
+
transform({ options, values }): MongoCredentials {
|
|
695
|
+
// We can have a combination of options passed in the URI and options passed
|
|
696
|
+
// as an object to the MongoClient. So we must transform the string options
|
|
697
|
+
// as well as merge them together with a potentially provided object.
|
|
698
|
+
let mechanismProperties = Object.create(null);
|
|
699
|
+
|
|
700
|
+
for (const optionValue of values) {
|
|
701
|
+
if (typeof optionValue === 'string') {
|
|
702
|
+
for (const [key, value] of entriesFromString(optionValue)) {
|
|
703
|
+
try {
|
|
704
|
+
mechanismProperties[key] = getBoolean(key, value);
|
|
705
|
+
} catch {
|
|
706
|
+
mechanismProperties[key] = value;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
} else {
|
|
710
|
+
if (!isRecord(optionValue)) {
|
|
711
|
+
throw new MongoParseError('AuthMechanismProperties must be an object');
|
|
690
712
|
}
|
|
713
|
+
mechanismProperties = { ...optionValue };
|
|
691
714
|
}
|
|
692
|
-
|
|
693
|
-
return MongoCredentials.merge(options.credentials, {
|
|
694
|
-
mechanismProperties
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
if (!isRecord(optionValue)) {
|
|
698
|
-
throw new MongoParseError('AuthMechanismProperties must be an object');
|
|
699
715
|
}
|
|
700
|
-
return MongoCredentials.merge(options.credentials, {
|
|
716
|
+
return MongoCredentials.merge(options.credentials, {
|
|
717
|
+
mechanismProperties
|
|
718
|
+
});
|
|
701
719
|
}
|
|
702
720
|
},
|
|
703
721
|
authSource: {
|
|
@@ -778,15 +796,8 @@ export const OPTIONS = {
|
|
|
778
796
|
type: 'boolean'
|
|
779
797
|
},
|
|
780
798
|
driverInfo: {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
transform({ options, values: [value] }) {
|
|
784
|
-
if (!isRecord(value)) throw new MongoParseError('DriverInfo must be an object');
|
|
785
|
-
return makeClientMetadata({
|
|
786
|
-
driverInfo: value,
|
|
787
|
-
appName: options.metadata?.application?.name
|
|
788
|
-
});
|
|
789
|
-
}
|
|
799
|
+
default: {},
|
|
800
|
+
type: 'record'
|
|
790
801
|
},
|
|
791
802
|
enableUtf8Validation: { type: 'boolean', default: true },
|
|
792
803
|
family: {
|
|
@@ -945,6 +956,9 @@ export const OPTIONS = {
|
|
|
945
956
|
promoteValues: {
|
|
946
957
|
type: 'boolean'
|
|
947
958
|
},
|
|
959
|
+
useBigInt64: {
|
|
960
|
+
type: 'boolean'
|
|
961
|
+
},
|
|
948
962
|
proxyHost: {
|
|
949
963
|
type: 'string'
|
|
950
964
|
},
|
|
@@ -1260,7 +1274,10 @@ export const OPTIONS = {
|
|
|
1260
1274
|
index: { type: 'any' },
|
|
1261
1275
|
// Legacy Options, these are unused but left here to avoid errors with CSFLE lib
|
|
1262
1276
|
useNewUrlParser: { type: 'boolean' } as OptionDescriptor,
|
|
1263
|
-
useUnifiedTopology: { type: 'boolean' } as OptionDescriptor
|
|
1277
|
+
useUnifiedTopology: { type: 'boolean' } as OptionDescriptor,
|
|
1278
|
+
// MongoLogger
|
|
1279
|
+
// TODO(NODE-4849): Tighten the type of mongodbLogPath
|
|
1280
|
+
mongodbLogPath: { type: 'any' }
|
|
1264
1281
|
} as Record<keyof MongoClientOptions, OptionDescriptor>;
|
|
1265
1282
|
|
|
1266
1283
|
export const DEFAULT_OPTIONS = new CaseInsensitiveMap(
|
|
@@ -65,7 +65,7 @@ export interface CursorStreamOptions {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/** @public */
|
|
68
|
-
export type CursorFlag = typeof CURSOR_FLAGS[number];
|
|
68
|
+
export type CursorFlag = (typeof CURSOR_FLAGS)[number];
|
|
69
69
|
|
|
70
70
|
/** @public */
|
|
71
71
|
export interface AbstractCursorOptions extends BSONSerializeOptions {
|
|
@@ -557,7 +557,7 @@ export abstract class AbstractCursor<
|
|
|
557
557
|
/**
|
|
558
558
|
* Set the batch size for the cursor.
|
|
559
559
|
*
|
|
560
|
-
* @param value - The number of documents to return per batch. See {@link https://
|
|
560
|
+
* @param value - The number of documents to return per batch. See {@link https://www.mongodb.com/docs/manual/reference/command/find/|find command documentation}.
|
|
561
561
|
*/
|
|
562
562
|
batchSize(value: number): this {
|
|
563
563
|
assertUninitialized(this);
|
|
@@ -642,6 +642,8 @@ export abstract class AbstractCursor<
|
|
|
642
642
|
this[kId] =
|
|
643
643
|
typeof response.cursor.id === 'number'
|
|
644
644
|
? Long.fromNumber(response.cursor.id)
|
|
645
|
+
: typeof response.cursor.id === 'bigint'
|
|
646
|
+
? Long.fromBigInt(response.cursor.id)
|
|
645
647
|
: response.cursor.id;
|
|
646
648
|
|
|
647
649
|
if (response.cursor.ns) {
|
|
@@ -741,6 +743,8 @@ export function next<T>(
|
|
|
741
743
|
const cursorId =
|
|
742
744
|
typeof response.cursor.id === 'number'
|
|
743
745
|
? Long.fromNumber(response.cursor.id)
|
|
746
|
+
: typeof response.cursor.id === 'bigint'
|
|
747
|
+
? Long.fromBigInt(response.cursor.id)
|
|
744
748
|
: response.cursor.id;
|
|
745
749
|
|
|
746
750
|
cursor[kDocuments].pushMany(response.cursor.nextBatch);
|
|
@@ -828,13 +832,16 @@ function cleanupCursor(
|
|
|
828
832
|
|
|
829
833
|
cursor[kKilled] = true;
|
|
830
834
|
|
|
835
|
+
if (session.hasEnded) {
|
|
836
|
+
return completeCleanup();
|
|
837
|
+
}
|
|
838
|
+
|
|
831
839
|
executeOperation(
|
|
832
840
|
cursor[kClient],
|
|
833
841
|
new KillCursorsOperation(cursorId, cursorNs, server, { session })
|
|
834
|
-
)
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
return;
|
|
842
|
+
)
|
|
843
|
+
.catch(() => null)
|
|
844
|
+
.finally(completeCleanup);
|
|
838
845
|
}
|
|
839
846
|
|
|
840
847
|
/** @internal */
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { Document, Long, Timestamp } from '../bson';
|
|
2
2
|
import {
|
|
3
|
+
ChangeStream,
|
|
3
4
|
type ChangeStreamDocument,
|
|
4
5
|
type ChangeStreamEvents,
|
|
5
6
|
type OperationTime,
|
|
6
|
-
type ResumeToken
|
|
7
|
-
ChangeStream
|
|
7
|
+
type ResumeToken
|
|
8
8
|
} from '../change_stream';
|
|
9
9
|
import { INIT, RESPONSE } from '../constants';
|
|
10
10
|
import type { MongoClient } from '../mongo_client';
|
|
11
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 { type ExecutionResult
|
|
14
|
+
import { executeOperation, type ExecutionResult } from '../operations/execute_operation';
|
|
15
15
|
import type { ClientSession } from '../sessions';
|
|
16
|
-
import { type Callback, type MongoDBNamespace
|
|
17
|
-
import { type AbstractCursorOptions
|
|
16
|
+
import { type Callback, maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
17
|
+
import { AbstractCursor, type AbstractCursorOptions } from './abstract_cursor';
|
|
18
18
|
|
|
19
19
|
/** @internal */
|
|
20
20
|
export interface ChangeStreamCursorOptions extends AbstractCursorOptions {
|
|
@@ -386,7 +386,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
386
386
|
* Allows disk use for blocking sort operations exceeding 100MB memory. (MongoDB 3.2 or higher)
|
|
387
387
|
*
|
|
388
388
|
* @remarks
|
|
389
|
-
* {@link https://
|
|
389
|
+
* {@link https://www.mongodb.com/docs/manual/reference/command/find/#find-cmd-allowdiskuse | find command allowDiskUse documentation}
|
|
390
390
|
*/
|
|
391
391
|
allowDiskUse(allow = true): this {
|
|
392
392
|
assertUninitialized(this);
|
package/src/db.ts
CHANGED
|
@@ -57,6 +57,7 @@ const DB_OPTIONS_ALLOW_LIST = [
|
|
|
57
57
|
'readConcern',
|
|
58
58
|
'retryMiliSeconds',
|
|
59
59
|
'numberOfRetries',
|
|
60
|
+
'useBigInt64',
|
|
60
61
|
'promoteBuffers',
|
|
61
62
|
'promoteLongs',
|
|
62
63
|
'bsonRegExp',
|
|
@@ -210,7 +211,7 @@ export class Db {
|
|
|
210
211
|
|
|
211
212
|
/**
|
|
212
213
|
* Create a new collection on a server with the specified options. Use this to create capped collections.
|
|
213
|
-
* More information about command options available at https://
|
|
214
|
+
* More information about command options available at https://www.mongodb.com/docs/manual/reference/command/create/
|
|
214
215
|
*
|
|
215
216
|
* @param name - The name of the collection to create
|
|
216
217
|
* @param options - Optional settings for the command
|
|
@@ -487,7 +488,7 @@ export class Db {
|
|
|
487
488
|
* - The first is to provide the schema that may be defined for all the collections within this database
|
|
488
489
|
* - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
|
|
489
490
|
*
|
|
490
|
-
* @param pipeline - An array of {@link https://
|
|
491
|
+
* @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
|
|
491
492
|
* @param options - Optional settings for the command
|
|
492
493
|
* @typeParam TSchema - Type of the data being detected by the change stream
|
|
493
494
|
* @typeParam TChange - Type of the whole change stream document emitted
|