mongodb 4.5.0 → 4.7.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/lib/admin.js +5 -5
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +7 -4
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +264 -258
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +3 -0
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/scram.js +12 -1
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/commands.js +12 -11
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +8 -1
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +9 -60
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +70 -57
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/message_stream.js +39 -6
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +18 -2
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +2 -2
- package/lib/cmap/wire_protocol/shared.js +3 -0
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +62 -31
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +39 -11
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +8 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +16 -11
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +5 -5
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +12 -7
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +21 -14
- package/lib/db.js.map +1 -1
- package/lib/deps.js +6 -1
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +13 -3
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +37 -24
- package/lib/error.js.map +1 -1
- package/lib/gridfs/upload.js +1 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +18 -0
- package/lib/mongo_client.js.map +1 -1
- package/lib/operations/command.js +0 -3
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/connect.js +1 -0
- package/lib/operations/connect.js.map +1 -1
- package/lib/operations/create_collection.js +56 -17
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/drop.js +48 -7
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js +1 -20
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/execute_operation.js +16 -9
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +0 -51
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/indexes.js +2 -2
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +5 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/list_collections.js +2 -2
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/sdam/monitor.js +10 -3
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +29 -21
- package/lib/sdam/server.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 +25 -24
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +2 -1
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +29 -17
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +3 -2
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +521 -88
- package/package.json +12 -11
- package/src/admin.ts +9 -5
- package/src/bulk/common.ts +7 -4
- package/src/change_stream.ts +761 -440
- package/src/cmap/auth/mongodb_aws.ts +5 -0
- package/src/cmap/auth/scram.ts +11 -1
- package/src/cmap/commands.ts +23 -22
- package/src/cmap/connect.ts +13 -2
- package/src/cmap/connection.ts +12 -74
- package/src/cmap/connection_pool.ts +90 -74
- package/src/cmap/connection_pool_events.ts +1 -1
- package/src/cmap/message_stream.ts +41 -7
- package/src/cmap/wire_protocol/compression.ts +27 -3
- package/src/cmap/wire_protocol/constants.ts +2 -2
- package/src/cmap/wire_protocol/shared.ts +5 -1
- package/src/collection.ts +74 -36
- package/src/connection_string.ts +49 -14
- package/src/constants.ts +6 -0
- package/src/cursor/abstract_cursor.ts +18 -15
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +16 -8
- package/src/db.ts +31 -20
- package/src/deps.ts +65 -7
- package/src/encrypter.ts +12 -3
- package/src/error.ts +41 -27
- package/src/gridfs/upload.ts +1 -1
- package/src/index.ts +23 -0
- package/src/mongo_client.ts +36 -11
- package/src/mongo_types.ts +1 -1
- package/src/operations/command.ts +0 -4
- package/src/operations/connect.ts +1 -0
- package/src/operations/create_collection.ts +95 -21
- package/src/operations/drop.ts +66 -6
- package/src/operations/estimated_document_count.ts +2 -29
- package/src/operations/execute_operation.ts +27 -27
- package/src/operations/find.ts +0 -80
- package/src/operations/indexes.ts +3 -9
- package/src/operations/insert.ts +8 -1
- package/src/operations/list_collections.ts +3 -3
- package/src/sdam/monitor.ts +10 -0
- package/src/sdam/server.ts +39 -36
- package/src/sdam/srv_polling.ts +1 -0
- package/src/sdam/topology.ts +36 -27
- package/src/sdam/topology_description.ts +2 -1
- package/src/sessions.ts +31 -20
- package/src/transactions.ts +1 -1
- package/src/utils.ts +3 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
2
|
import type { ExplainVerbosityLike } from '../explain';
|
|
3
|
+
import type { MongoClient } from '../mongo_client';
|
|
3
4
|
import { AggregateOperation, AggregateOptions } from '../operations/aggregate';
|
|
4
5
|
import { executeOperation, ExecutionResult } from '../operations/execute_operation';
|
|
5
|
-
import type { Topology } from '../sdam/topology';
|
|
6
6
|
import type { ClientSession } from '../sessions';
|
|
7
7
|
import type { Sort } from '../sort';
|
|
8
8
|
import type { Callback, MongoDBNamespace } from '../utils';
|
|
@@ -33,12 +33,12 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
33
33
|
|
|
34
34
|
/** @internal */
|
|
35
35
|
constructor(
|
|
36
|
-
|
|
36
|
+
client: MongoClient,
|
|
37
37
|
namespace: MongoDBNamespace,
|
|
38
38
|
pipeline: Document[] = [],
|
|
39
39
|
options: AggregateOptions = {}
|
|
40
40
|
) {
|
|
41
|
-
super(
|
|
41
|
+
super(client, namespace, options);
|
|
42
42
|
|
|
43
43
|
this[kPipeline] = pipeline;
|
|
44
44
|
this[kOptions] = options;
|
|
@@ -51,7 +51,7 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
51
51
|
clone(): AggregationCursor<TSchema> {
|
|
52
52
|
const clonedOptions = mergeOptions({}, this[kOptions]);
|
|
53
53
|
delete clonedOptions.session;
|
|
54
|
-
return new AggregationCursor(this.
|
|
54
|
+
return new AggregationCursor(this.client, this.namespace, this[kPipeline], {
|
|
55
55
|
...clonedOptions
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -68,7 +68,7 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
68
68
|
session
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
executeOperation(this, aggregateOperation, (err, response) => {
|
|
71
|
+
executeOperation(this.client, aggregateOperation, (err, response) => {
|
|
72
72
|
if (err || response == null) return callback(err);
|
|
73
73
|
|
|
74
74
|
// TODO: NODE-2882
|
|
@@ -88,7 +88,7 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
88
88
|
if (verbosity == null) verbosity = true;
|
|
89
89
|
|
|
90
90
|
return executeOperation(
|
|
91
|
-
this,
|
|
91
|
+
this.client,
|
|
92
92
|
new AggregateOperation(this.namespace, this[kPipeline], {
|
|
93
93
|
...this[kOptions], // NOTE: order matters here, we may need to refine this
|
|
94
94
|
...this.cursorOptions,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
2
|
import { MongoInvalidArgumentError, MongoTailableCursorError } from '../error';
|
|
3
3
|
import type { ExplainVerbosityLike } from '../explain';
|
|
4
|
+
import type { MongoClient } from '../mongo_client';
|
|
4
5
|
import type { CollationOptions } from '../operations/command';
|
|
5
6
|
import { CountOperation, CountOptions } from '../operations/count';
|
|
6
7
|
import { executeOperation, ExecutionResult } from '../operations/execute_operation';
|
|
7
8
|
import { FindOperation, FindOptions } from '../operations/find';
|
|
8
9
|
import type { Hint } from '../operations/operation';
|
|
9
|
-
import type { Topology } from '../sdam/topology';
|
|
10
10
|
import type { ClientSession } from '../sessions';
|
|
11
11
|
import { formatSort, Sort, SortDirection } from '../sort';
|
|
12
12
|
import { Callback, emitWarningOnce, mergeOptions, MongoDBNamespace } from '../utils';
|
|
@@ -40,12 +40,12 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
40
40
|
|
|
41
41
|
/** @internal */
|
|
42
42
|
constructor(
|
|
43
|
-
|
|
43
|
+
client: MongoClient,
|
|
44
44
|
namespace: MongoDBNamespace,
|
|
45
45
|
filter: Document | undefined,
|
|
46
46
|
options: FindOptions = {}
|
|
47
47
|
) {
|
|
48
|
-
super(
|
|
48
|
+
super(client, namespace, options);
|
|
49
49
|
|
|
50
50
|
this[kFilter] = filter || {};
|
|
51
51
|
this[kBuiltOptions] = options;
|
|
@@ -58,7 +58,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
58
58
|
clone(): FindCursor<TSchema> {
|
|
59
59
|
const clonedOptions = mergeOptions({}, this[kBuiltOptions]);
|
|
60
60
|
delete clonedOptions.session;
|
|
61
|
-
return new FindCursor(this.
|
|
61
|
+
return new FindCursor(this.client, this.namespace, this[kFilter], {
|
|
62
62
|
...clonedOptions
|
|
63
63
|
});
|
|
64
64
|
}
|
|
@@ -75,7 +75,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
75
75
|
session
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
executeOperation(this, findOperation, (err, response) => {
|
|
78
|
+
executeOperation(this.client, findOperation, (err, response) => {
|
|
79
79
|
if (err || response == null) return callback(err);
|
|
80
80
|
|
|
81
81
|
// TODO: We only need this for legacy queries that do not support `limit`, maybe
|
|
@@ -143,7 +143,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
143
143
|
options = options ?? {};
|
|
144
144
|
|
|
145
145
|
return executeOperation(
|
|
146
|
-
this,
|
|
146
|
+
this.client,
|
|
147
147
|
new CountOperation(this.namespace, this[kFilter], {
|
|
148
148
|
...this[kBuiltOptions], // NOTE: order matters here, we may need to refine this
|
|
149
149
|
...this.cursorOptions,
|
|
@@ -165,7 +165,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
165
165
|
if (verbosity == null) verbosity = true;
|
|
166
166
|
|
|
167
167
|
return executeOperation(
|
|
168
|
-
this,
|
|
168
|
+
this.client,
|
|
169
169
|
new FindOperation(undefined, this.namespace, this[kFilter], {
|
|
170
170
|
...this[kBuiltOptions], // NOTE: order matters here, we may need to refine this
|
|
171
171
|
...this.cursorOptions,
|
|
@@ -412,11 +412,19 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
412
412
|
* @remarks
|
|
413
413
|
* {@link https://docs.mongodb.com/manual/reference/command/find/#find-cmd-allowdiskuse | find command allowDiskUse documentation}
|
|
414
414
|
*/
|
|
415
|
-
allowDiskUse(): this {
|
|
415
|
+
allowDiskUse(allow = true): this {
|
|
416
416
|
assertUninitialized(this);
|
|
417
|
+
|
|
417
418
|
if (!this[kBuiltOptions].sort) {
|
|
418
419
|
throw new MongoInvalidArgumentError('Option "allowDiskUse" requires a sort specification');
|
|
419
420
|
}
|
|
421
|
+
|
|
422
|
+
// As of 6.0 the default is true. This allows users to get back to the old behaviour.
|
|
423
|
+
if (!allow) {
|
|
424
|
+
this[kBuiltOptions].allowDiskUse = false;
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
|
|
420
428
|
this[kBuiltOptions].allowDiskUse = true;
|
|
421
429
|
return this;
|
|
422
430
|
}
|
package/src/db.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Admin } from './admin';
|
|
2
2
|
import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
|
|
3
|
-
import { ChangeStream, ChangeStreamOptions } from './change_stream';
|
|
3
|
+
import { ChangeStream, ChangeStreamDocument, ChangeStreamOptions } from './change_stream';
|
|
4
4
|
import { Collection, CollectionOptions } from './collection';
|
|
5
5
|
import * as CONSTANTS from './constants';
|
|
6
6
|
import { AggregationCursor } from './cursor/aggregation_cursor';
|
|
@@ -258,7 +258,7 @@ export class Db {
|
|
|
258
258
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
259
259
|
|
|
260
260
|
return executeOperation(
|
|
261
|
-
this,
|
|
261
|
+
this.s.client,
|
|
262
262
|
new CreateCollectionOperation(this, name, resolveOptions(this, options)) as TODO_NODE_3286,
|
|
263
263
|
callback
|
|
264
264
|
) as TODO_NODE_3286;
|
|
@@ -286,7 +286,11 @@ export class Db {
|
|
|
286
286
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
287
287
|
|
|
288
288
|
// Intentionally, we do not inherit options from parent for this operation.
|
|
289
|
-
return executeOperation(
|
|
289
|
+
return executeOperation(
|
|
290
|
+
this.s.client,
|
|
291
|
+
new RunCommandOperation(this, command, options ?? {}),
|
|
292
|
+
callback
|
|
293
|
+
);
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
/**
|
|
@@ -310,7 +314,7 @@ export class Db {
|
|
|
310
314
|
}
|
|
311
315
|
|
|
312
316
|
return new AggregationCursor(
|
|
313
|
-
|
|
317
|
+
this.s.client,
|
|
314
318
|
this.s.namespace,
|
|
315
319
|
pipeline,
|
|
316
320
|
resolveOptions(this, options)
|
|
@@ -355,7 +359,7 @@ export class Db {
|
|
|
355
359
|
): Promise<Document> | void {
|
|
356
360
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
357
361
|
return executeOperation(
|
|
358
|
-
this,
|
|
362
|
+
this.s.client,
|
|
359
363
|
new DbStatsOperation(this, resolveOptions(this, options)),
|
|
360
364
|
callback
|
|
361
365
|
);
|
|
@@ -434,7 +438,7 @@ export class Db {
|
|
|
434
438
|
options.new_collection = true;
|
|
435
439
|
|
|
436
440
|
return executeOperation(
|
|
437
|
-
this,
|
|
441
|
+
this.s.client,
|
|
438
442
|
new RenameOperation(
|
|
439
443
|
this.collection<TSchema>(fromCollection) as TODO_NODE_3286,
|
|
440
444
|
toCollection,
|
|
@@ -463,7 +467,7 @@ export class Db {
|
|
|
463
467
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
464
468
|
|
|
465
469
|
return executeOperation(
|
|
466
|
-
this,
|
|
470
|
+
this.s.client,
|
|
467
471
|
new DropCollectionOperation(this, name, resolveOptions(this, options)),
|
|
468
472
|
callback
|
|
469
473
|
);
|
|
@@ -486,7 +490,7 @@ export class Db {
|
|
|
486
490
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
487
491
|
|
|
488
492
|
return executeOperation(
|
|
489
|
-
this,
|
|
493
|
+
this.s.client,
|
|
490
494
|
new DropDatabaseOperation(this, resolveOptions(this, options)),
|
|
491
495
|
callback
|
|
492
496
|
);
|
|
@@ -509,7 +513,7 @@ export class Db {
|
|
|
509
513
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
510
514
|
|
|
511
515
|
return executeOperation(
|
|
512
|
-
this,
|
|
516
|
+
this.s.client,
|
|
513
517
|
new CollectionsOperation(this, resolveOptions(this, options)),
|
|
514
518
|
callback
|
|
515
519
|
);
|
|
@@ -545,7 +549,7 @@ export class Db {
|
|
|
545
549
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
546
550
|
|
|
547
551
|
return executeOperation(
|
|
548
|
-
this,
|
|
552
|
+
this.s.client,
|
|
549
553
|
new CreateIndexOperation(this, name, indexSpec, resolveOptions(this, options)),
|
|
550
554
|
callback
|
|
551
555
|
);
|
|
@@ -591,7 +595,7 @@ export class Db {
|
|
|
591
595
|
}
|
|
592
596
|
|
|
593
597
|
return executeOperation(
|
|
594
|
-
this,
|
|
598
|
+
this.s.client,
|
|
595
599
|
new AddUserOperation(this, username, password, resolveOptions(this, options)),
|
|
596
600
|
callback
|
|
597
601
|
);
|
|
@@ -616,7 +620,7 @@ export class Db {
|
|
|
616
620
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
617
621
|
|
|
618
622
|
return executeOperation(
|
|
619
|
-
this,
|
|
623
|
+
this.s.client,
|
|
620
624
|
new RemoveUserOperation(this, username, resolveOptions(this, options)),
|
|
621
625
|
callback
|
|
622
626
|
);
|
|
@@ -648,7 +652,7 @@ export class Db {
|
|
|
648
652
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
649
653
|
|
|
650
654
|
return executeOperation(
|
|
651
|
-
this,
|
|
655
|
+
this.s.client,
|
|
652
656
|
new SetProfilingLevelOperation(this, level, resolveOptions(this, options)),
|
|
653
657
|
callback
|
|
654
658
|
);
|
|
@@ -671,7 +675,7 @@ export class Db {
|
|
|
671
675
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
672
676
|
|
|
673
677
|
return executeOperation(
|
|
674
|
-
this,
|
|
678
|
+
this.s.client,
|
|
675
679
|
new ProfilingLevelOperation(this, resolveOptions(this, options)),
|
|
676
680
|
callback
|
|
677
681
|
);
|
|
@@ -700,7 +704,7 @@ export class Db {
|
|
|
700
704
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
701
705
|
|
|
702
706
|
return executeOperation(
|
|
703
|
-
this,
|
|
707
|
+
this.s.client,
|
|
704
708
|
new IndexInformationOperation(this, name, resolveOptions(this, options)),
|
|
705
709
|
callback
|
|
706
710
|
);
|
|
@@ -719,20 +723,27 @@ export class Db {
|
|
|
719
723
|
* replacements, deletions, and invalidations) in this database. Will ignore all
|
|
720
724
|
* changes to system collections.
|
|
721
725
|
*
|
|
726
|
+
* @remarks
|
|
727
|
+
* watch() accepts two generic arguments for distinct usecases:
|
|
728
|
+
* - The first is to provide the schema that may be defined for all the collections within this database
|
|
729
|
+
* - 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
|
|
730
|
+
*
|
|
722
731
|
* @param pipeline - An array of {@link https://docs.mongodb.com/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.
|
|
723
732
|
* @param options - Optional settings for the command
|
|
733
|
+
* @typeParam TSchema - Type of the data being detected by the change stream
|
|
734
|
+
* @typeParam TChange - Type of the whole change stream document emitted
|
|
724
735
|
*/
|
|
725
|
-
watch<
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
): ChangeStream<TSchema> {
|
|
736
|
+
watch<
|
|
737
|
+
TSchema extends Document = Document,
|
|
738
|
+
TChange extends Document = ChangeStreamDocument<TSchema>
|
|
739
|
+
>(pipeline: Document[] = [], options: ChangeStreamOptions = {}): ChangeStream<TSchema, TChange> {
|
|
729
740
|
// Allow optionally not specifying a pipeline
|
|
730
741
|
if (!Array.isArray(pipeline)) {
|
|
731
742
|
options = pipeline;
|
|
732
743
|
pipeline = [];
|
|
733
744
|
}
|
|
734
745
|
|
|
735
|
-
return new ChangeStream<TSchema>(this, pipeline, resolveOptions(this, options));
|
|
746
|
+
return new ChangeStream<TSchema, TChange>(this, pipeline, resolveOptions(this, options));
|
|
736
747
|
}
|
|
737
748
|
|
|
738
749
|
/** Return the db logger */
|
package/src/deps.ts
CHANGED
|
@@ -44,6 +44,30 @@ export interface KerberosClient {
|
|
|
44
44
|
unwrap: (challenge: string, callback?: Callback<string>) => Promise<string> | void;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
type ZStandardLib = {
|
|
48
|
+
/**
|
|
49
|
+
* Compress using zstd.
|
|
50
|
+
* @param buf - Buffer to be compressed.
|
|
51
|
+
*/
|
|
52
|
+
compress(buf: Buffer, level?: number): Promise<Buffer>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Decompress using zstd.
|
|
56
|
+
*/
|
|
57
|
+
decompress(buf: Buffer): Promise<Buffer>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export let ZStandard: ZStandardLib | { kModuleError: MongoMissingDependencyError } =
|
|
61
|
+
makeErrorModule(
|
|
62
|
+
new MongoMissingDependencyError(
|
|
63
|
+
'Optional module `@mongodb-js/zstd` not found. Please install it to enable zstd compression'
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
ZStandard = require('@mongodb-js/zstd');
|
|
69
|
+
} catch {} // eslint-disable-line
|
|
70
|
+
|
|
47
71
|
type SnappyLib = {
|
|
48
72
|
[PKG_VERSION]: { major: number; minor: number; patch: number };
|
|
49
73
|
|
|
@@ -277,8 +301,12 @@ export interface AutoEncryptionOptions {
|
|
|
277
301
|
* Other validation rules in the JSON schema will not be enforced by the driver and will result in an error.
|
|
278
302
|
*/
|
|
279
303
|
schemaMap?: Document;
|
|
304
|
+
/** @experimental */
|
|
305
|
+
encryptedFieldsMap?: Document;
|
|
280
306
|
/** Allows the user to bypass auto encryption, maintaining implicit decryption */
|
|
281
307
|
bypassAutoEncryption?: boolean;
|
|
308
|
+
/** @experimental */
|
|
309
|
+
bypassQueryAnalysis?: boolean;
|
|
282
310
|
options?: {
|
|
283
311
|
/** An optional hook to catch logging messages from the underlying encryption engine */
|
|
284
312
|
logger?: (level: AutoEncryptionLoggerLevel, message: string) => void;
|
|
@@ -296,15 +324,44 @@ export interface AutoEncryptionOptions {
|
|
|
296
324
|
/** Command line arguments to use when auto-spawning a mongocryptd */
|
|
297
325
|
mongocryptdSpawnArgs?: string[];
|
|
298
326
|
/**
|
|
299
|
-
* Full path to a
|
|
300
|
-
*
|
|
327
|
+
* Full path to a MongoDB Crypt shared library to be used (instead of mongocryptd).
|
|
328
|
+
*
|
|
329
|
+
* This needs to be the path to the file itself, not a directory.
|
|
330
|
+
* It can be an absolute or relative path. If the path is relative and
|
|
331
|
+
* its first component is `$ORIGIN`, it will be replaced by the directory
|
|
332
|
+
* containing the mongodb-client-encryption native addon file. Otherwise,
|
|
333
|
+
* the path will be interpreted relative to the current working directory.
|
|
334
|
+
*
|
|
335
|
+
* Currently, loading different MongoDB Crypt shared library files from different
|
|
336
|
+
* MongoClients in the same process is not supported.
|
|
337
|
+
*
|
|
338
|
+
* If this option is provided and no MongoDB Crypt shared library could be loaded
|
|
339
|
+
* from the specified location, creating the MongoClient will fail.
|
|
340
|
+
*
|
|
341
|
+
* If this option is not provided and `cryptSharedLibRequired` is not specified,
|
|
342
|
+
* the AutoEncrypter will attempt to spawn and/or use mongocryptd according
|
|
343
|
+
* to the mongocryptd-specific `extraOptions` options.
|
|
344
|
+
*
|
|
345
|
+
* Specifying a path prevents mongocryptd from being used as a fallback.
|
|
346
|
+
*
|
|
347
|
+
* @experimental Requires the MongoDB Crypt shared library, available in MongoDB 6.0 or higher.
|
|
348
|
+
*/
|
|
349
|
+
cryptSharedLibPath?: string;
|
|
350
|
+
/**
|
|
351
|
+
* If specified, never use mongocryptd and instead fail when the MongoDB Crypt
|
|
352
|
+
* shared library could not be loaded.
|
|
353
|
+
*
|
|
354
|
+
* This is always true when `cryptSharedLibPath` is specified.
|
|
355
|
+
*
|
|
356
|
+
* @experimental Requires the MongoDB Crypt shared library, available in MongoDB 6.0 or higher.
|
|
301
357
|
*/
|
|
302
|
-
|
|
358
|
+
cryptSharedLibRequired?: boolean;
|
|
303
359
|
/**
|
|
304
|
-
* Search paths for a
|
|
305
|
-
*
|
|
360
|
+
* Search paths for a MongoDB Crypt shared library to be used (instead of mongocryptd)
|
|
361
|
+
* Only for driver testing!
|
|
362
|
+
* @internal
|
|
306
363
|
*/
|
|
307
|
-
|
|
364
|
+
cryptSharedLibSearchPaths?: string[];
|
|
308
365
|
};
|
|
309
366
|
proxyOptions?: ProxyOptions;
|
|
310
367
|
/** The TLS options to use connecting to the KMS provider */
|
|
@@ -325,5 +382,6 @@ export interface AutoEncrypter {
|
|
|
325
382
|
teardown(force: boolean, callback: Callback): void;
|
|
326
383
|
encrypt(ns: string, cmd: Document, options: any, callback: Callback<Document>): void;
|
|
327
384
|
decrypt(cmd: Document, options: any, callback: Callback<Document>): void;
|
|
328
|
-
|
|
385
|
+
/** @experimental */
|
|
386
|
+
readonly cryptSharedLibVersionInfo: { version: bigint; versionStr: string } | null;
|
|
329
387
|
}
|
package/src/encrypter.ts
CHANGED
|
@@ -72,7 +72,10 @@ export class Encrypter {
|
|
|
72
72
|
if (internalClient == null) {
|
|
73
73
|
const clonedOptions: MongoClientOptions = {};
|
|
74
74
|
|
|
75
|
-
for (const key of
|
|
75
|
+
for (const key of [
|
|
76
|
+
...Object.getOwnPropertyNames(options),
|
|
77
|
+
...Object.getOwnPropertySymbols(options)
|
|
78
|
+
] as string[]) {
|
|
76
79
|
if (['autoEncryption', 'minPoolSize', 'servers', 'caseTranslate', 'dbName'].includes(key))
|
|
77
80
|
continue;
|
|
78
81
|
Reflect.set(clonedOptions, key, Reflect.get(options, key));
|
|
@@ -121,9 +124,15 @@ export class Encrypter {
|
|
|
121
124
|
|
|
122
125
|
static checkForMongoCrypt(): void {
|
|
123
126
|
let mongodbClientEncryption = undefined;
|
|
127
|
+
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
124
128
|
try {
|
|
125
|
-
//
|
|
126
|
-
|
|
129
|
+
// Note (NODE-4254): This is to get around the circular dependency between
|
|
130
|
+
// mongodb-client-encryption and the driver in the test scenarios.
|
|
131
|
+
if (process.env.MONGODB_CLIENT_ENCRYPTION_OVERRIDE) {
|
|
132
|
+
mongodbClientEncryption = require(process.env.MONGODB_CLIENT_ENCRYPTION_OVERRIDE);
|
|
133
|
+
} else {
|
|
134
|
+
mongodbClientEncryption = require('mongodb-client-encryption');
|
|
135
|
+
}
|
|
127
136
|
} catch (err) {
|
|
128
137
|
throw new MongoMissingDependencyError(
|
|
129
138
|
'Auto-encryption requested, but the module is not installed. ' +
|
package/src/error.ts
CHANGED
|
@@ -88,7 +88,8 @@ export const MongoErrorLabel = Object.freeze({
|
|
|
88
88
|
RetryableWriteError: 'RetryableWriteError',
|
|
89
89
|
TransientTransactionError: 'TransientTransactionError',
|
|
90
90
|
UnknownTransactionCommitResult: 'UnknownTransactionCommitResult',
|
|
91
|
-
ResumableChangeStreamError: 'ResumableChangeStreamError'
|
|
91
|
+
ResumableChangeStreamError: 'ResumableChangeStreamError',
|
|
92
|
+
HandshakeError: 'HandshakeError'
|
|
92
93
|
} as const);
|
|
93
94
|
|
|
94
95
|
/** @public */
|
|
@@ -346,6 +347,23 @@ export class MongoKerberosError extends MongoRuntimeError {
|
|
|
346
347
|
}
|
|
347
348
|
}
|
|
348
349
|
|
|
350
|
+
/**
|
|
351
|
+
* A error generated when the user attempts to authenticate
|
|
352
|
+
* via AWS, but fails
|
|
353
|
+
*
|
|
354
|
+
* @public
|
|
355
|
+
* @category Error
|
|
356
|
+
*/
|
|
357
|
+
export class MongoAWSError extends MongoRuntimeError {
|
|
358
|
+
constructor(message: string) {
|
|
359
|
+
super(message);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
override get name(): string {
|
|
363
|
+
return 'MongoAWSError';
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
349
367
|
/**
|
|
350
368
|
* An error generated when a ChangeStream operation fails to execute.
|
|
351
369
|
*
|
|
@@ -744,21 +762,22 @@ const RETRYABLE_WRITE_ERROR_CODES = new Set<number>([
|
|
|
744
762
|
]);
|
|
745
763
|
|
|
746
764
|
export function needsRetryableWriteLabel(error: Error, maxWireVersion: number): boolean {
|
|
747
|
-
if (maxWireVersion >= 9) {
|
|
748
|
-
// 4.4+ servers attach their own retryable write error
|
|
749
|
-
return false;
|
|
750
|
-
}
|
|
751
765
|
// pre-4.4 server, then the driver adds an error label for every valid case
|
|
752
766
|
// execute operation will only inspect the label, code/message logic is handled here
|
|
753
|
-
|
|
754
767
|
if (error instanceof MongoNetworkError) {
|
|
755
768
|
return true;
|
|
756
769
|
}
|
|
757
770
|
|
|
758
|
-
if (error instanceof MongoError
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
771
|
+
if (error instanceof MongoError) {
|
|
772
|
+
if (
|
|
773
|
+
(maxWireVersion >= 9 || error.hasErrorLabel(MongoErrorLabel.RetryableWriteError)) &&
|
|
774
|
+
!error.hasErrorLabel(MongoErrorLabel.HandshakeError)
|
|
775
|
+
) {
|
|
776
|
+
// If we already have the error label no need to add it again. 4.4+ servers add the label.
|
|
777
|
+
// In the case where we have a handshake error, need to fall down to the logic checking
|
|
778
|
+
// the codes.
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
762
781
|
}
|
|
763
782
|
|
|
764
783
|
if (error instanceof MongoWriteConcernError) {
|
|
@@ -782,6 +801,10 @@ export function needsRetryableWriteLabel(error: Error, maxWireVersion: number):
|
|
|
782
801
|
return false;
|
|
783
802
|
}
|
|
784
803
|
|
|
804
|
+
export function isRetryableWriteError(error: MongoError): boolean {
|
|
805
|
+
return error.hasErrorLabel(MongoErrorLabel.RetryableWriteError);
|
|
806
|
+
}
|
|
807
|
+
|
|
785
808
|
/** Determines whether an error is something the driver should attempt to retry */
|
|
786
809
|
export function isRetryableReadError(error: MongoError): boolean {
|
|
787
810
|
const hasRetryableErrorCode =
|
|
@@ -876,35 +899,26 @@ export function isNetworkTimeoutError(err: MongoError): err is MongoNetworkError
|
|
|
876
899
|
return !!(err instanceof MongoNetworkError && err.message.match(/timed out/));
|
|
877
900
|
}
|
|
878
901
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
// - any server error response from a getMore command excluding those containing the error label
|
|
884
|
-
// NonRetryableChangeStreamError and those containing the following error codes:
|
|
885
|
-
// - Interrupted: 11601
|
|
886
|
-
// - CappedPositionLost: 136
|
|
887
|
-
// - CursorKilled: 237
|
|
888
|
-
//
|
|
889
|
-
// An error on an aggregate command is not a resumable error. Only errors on a getMore command may be considered resumable errors.
|
|
902
|
+
export function isResumableError(error?: Error, wireVersion?: number): boolean {
|
|
903
|
+
if (error == null || !(error instanceof MongoError)) {
|
|
904
|
+
return false;
|
|
905
|
+
}
|
|
890
906
|
|
|
891
|
-
export function isResumableError(error?: MongoError, wireVersion?: number): boolean {
|
|
892
907
|
if (error instanceof MongoNetworkError) {
|
|
893
908
|
return true;
|
|
894
909
|
}
|
|
895
910
|
|
|
896
911
|
if (wireVersion != null && wireVersion >= 9) {
|
|
897
912
|
// DRIVERS-1308: For 4.4 drivers running against 4.4 servers, drivers will add a special case to treat the CursorNotFound error code as resumable
|
|
898
|
-
if (error
|
|
913
|
+
if (error.code === MONGODB_ERROR_CODES.CursorNotFound) {
|
|
899
914
|
return true;
|
|
900
915
|
}
|
|
901
|
-
return (
|
|
902
|
-
error instanceof MongoError && error.hasErrorLabel(MongoErrorLabel.ResumableChangeStreamError)
|
|
903
|
-
);
|
|
916
|
+
return error.hasErrorLabel(MongoErrorLabel.ResumableChangeStreamError);
|
|
904
917
|
}
|
|
905
918
|
|
|
906
|
-
if (
|
|
919
|
+
if (typeof error.code === 'number') {
|
|
907
920
|
return GET_MORE_RESUMABLE_CODES.has(error.code);
|
|
908
921
|
}
|
|
922
|
+
|
|
909
923
|
return false;
|
|
910
924
|
}
|
package/src/gridfs/upload.ts
CHANGED
|
@@ -196,7 +196,7 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
|
|
|
196
196
|
? encodingOrCallback
|
|
197
197
|
: callback;
|
|
198
198
|
|
|
199
|
-
if (checkAborted(this, callback)) return this;
|
|
199
|
+
if (this.state.streamEnd || checkAborted(this, callback)) return this;
|
|
200
200
|
|
|
201
201
|
this.state.streamEnd = true;
|
|
202
202
|
|
package/src/index.ts
CHANGED
|
@@ -38,6 +38,7 @@ export const ObjectID = ObjectId;
|
|
|
38
38
|
export { AnyBulkWriteOperation, BulkWriteOptions, MongoBulkWriteError } from './bulk/common';
|
|
39
39
|
export {
|
|
40
40
|
MongoAPIError,
|
|
41
|
+
MongoAWSError,
|
|
41
42
|
MongoBatchReExecutionError,
|
|
42
43
|
MongoChangeStreamError,
|
|
43
44
|
MongoCompatibilityError,
|
|
@@ -169,11 +170,32 @@ export type { OrderedBulkOperation } from './bulk/ordered';
|
|
|
169
170
|
export type { UnorderedBulkOperation } from './bulk/unordered';
|
|
170
171
|
export type {
|
|
171
172
|
ChangeStream,
|
|
173
|
+
ChangeStreamAggregateRawResult,
|
|
174
|
+
ChangeStreamCollModDocument,
|
|
175
|
+
ChangeStreamCreateDocument,
|
|
176
|
+
ChangeStreamCreateIndexDocument,
|
|
172
177
|
ChangeStreamCursor,
|
|
173
178
|
ChangeStreamCursorOptions,
|
|
179
|
+
ChangeStreamDeleteDocument,
|
|
174
180
|
ChangeStreamDocument,
|
|
181
|
+
ChangeStreamDocumentCollectionUUID,
|
|
182
|
+
ChangeStreamDocumentCommon,
|
|
183
|
+
ChangeStreamDocumentKey,
|
|
184
|
+
ChangeStreamDocumentOperationDescription,
|
|
185
|
+
ChangeStreamDropDatabaseDocument,
|
|
186
|
+
ChangeStreamDropDocument,
|
|
187
|
+
ChangeStreamDropIndexDocument,
|
|
175
188
|
ChangeStreamEvents,
|
|
189
|
+
ChangeStreamInsertDocument,
|
|
190
|
+
ChangeStreamInvalidateDocument,
|
|
191
|
+
ChangeStreamNameSpace,
|
|
176
192
|
ChangeStreamOptions,
|
|
193
|
+
ChangeStreamRefineCollectionShardKeyDocument,
|
|
194
|
+
ChangeStreamRenameDocument,
|
|
195
|
+
ChangeStreamReplaceDocument,
|
|
196
|
+
ChangeStreamReshardCollectionDocument,
|
|
197
|
+
ChangeStreamShardCollectionDocument,
|
|
198
|
+
ChangeStreamUpdateDocument,
|
|
177
199
|
OperationTime,
|
|
178
200
|
PipeOptions,
|
|
179
201
|
ResumeOptions,
|
|
@@ -335,6 +357,7 @@ export type { IndexInformationOptions } from './operations/common_functions';
|
|
|
335
357
|
export type { CountOptions } from './operations/count';
|
|
336
358
|
export type { CountDocumentsOptions } from './operations/count_documents';
|
|
337
359
|
export type {
|
|
360
|
+
ClusteredCollectionOptions,
|
|
338
361
|
CreateCollectionOptions,
|
|
339
362
|
TimeSeriesCollectionOptions
|
|
340
363
|
} from './operations/create_collection';
|