mongodb 6.5.0-dev.20240326.sha.918fe69 → 6.5.0-dev.20240403.sha.cb5903f
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 +9 -9
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +33 -22
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +2 -1
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +21 -13
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +2 -2
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +6 -6
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/providers/azure.js +6 -3
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +6 -6
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
- package/lib/cmap/auth/scram.js +2 -2
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/connect.js +3 -3
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +7 -5
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +2 -1
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +2 -2
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +6 -6
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js +207 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/collection.js +25 -25
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +4 -6
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +44 -18
- 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 +16 -11
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +1 -1
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +11 -11
- package/lib/db.js.map +1 -1
- package/lib/encrypter.js +10 -4
- package/lib/encrypter.js.map +1 -1
- package/lib/gridfs/download.js +19 -14
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/upload.js +6 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/mongo_client.js +10 -5
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +3 -0
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/aggregate.js +2 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/delete.js +4 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/execute_operation.js +13 -3
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/get_more.js +1 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +2 -2
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +1 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/kill_cursors.js +3 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/run_command.js +4 -2
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/monitor.js +4 -0
- package/lib/sdam/monitor.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 +1 -1
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +6 -4
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +28 -2
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +7 -7
- package/package.json +3 -2
- package/src/admin.ts +9 -9
- package/src/bson.ts +13 -0
- package/src/bulk/common.ts +2 -1
- package/src/change_stream.ts +28 -21
- package/src/client-side-encryption/auto_encrypter.ts +2 -2
- package/src/client-side-encryption/client_encryption.ts +6 -6
- package/src/client-side-encryption/providers/azure.ts +5 -3
- package/src/cmap/auth/aws_temporary_credentials.ts +3 -1
- package/src/cmap/auth/gssapi.ts +7 -7
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
- package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
- package/src/cmap/auth/scram.ts +2 -2
- package/src/cmap/connect.ts +3 -3
- package/src/cmap/connection.ts +8 -5
- package/src/cmap/connection_pool.ts +2 -1
- package/src/cmap/handshake/client_metadata.ts +2 -5
- package/src/cmap/wire_protocol/compression.ts +6 -6
- package/src/cmap/wire_protocol/on_demand/document.ts +322 -0
- package/src/collection.ts +25 -25
- package/src/connection_string.ts +9 -7
- package/src/cursor/abstract_cursor.ts +40 -19
- package/src/cursor/aggregation_cursor.ts +1 -1
- package/src/cursor/find_cursor.ts +16 -12
- package/src/cursor/run_command_cursor.ts +1 -1
- package/src/db.ts +14 -11
- package/src/encrypter.ts +9 -4
- package/src/gridfs/download.ts +17 -31
- package/src/gridfs/upload.ts +9 -8
- package/src/mongo_client.ts +17 -12
- package/src/mongo_logger.ts +3 -0
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/command.ts +1 -1
- package/src/operations/delete.ts +4 -3
- package/src/operations/drop.ts +1 -1
- package/src/operations/execute_operation.ts +12 -4
- package/src/operations/find.ts +1 -1
- package/src/operations/get_more.ts +1 -1
- package/src/operations/indexes.ts +2 -2
- package/src/operations/insert.ts +1 -1
- package/src/operations/kill_cursors.ts +3 -2
- package/src/operations/list_collections.ts +5 -1
- package/src/operations/list_databases.ts +1 -1
- package/src/operations/run_command.ts +6 -4
- package/src/operations/stats.ts +1 -1
- package/src/operations/update.ts +7 -7
- package/src/sdam/monitor.ts +4 -0
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +1 -1
- package/src/sessions.ts +7 -4
- package/src/utils.ts +26 -1
|
@@ -20,7 +20,7 @@ import { ReadConcern, type ReadConcernLike } from '../read_concern';
|
|
|
20
20
|
import { ReadPreference, type ReadPreferenceLike } from '../read_preference';
|
|
21
21
|
import type { Server } from '../sdam/server';
|
|
22
22
|
import { ClientSession, maybeClearPinnedConnection } from '../sessions';
|
|
23
|
-
import { List, type MongoDBNamespace, ns } from '../utils';
|
|
23
|
+
import { List, type MongoDBNamespace, ns, squashError } from '../utils';
|
|
24
24
|
|
|
25
25
|
/** @internal */
|
|
26
26
|
const kId = Symbol('id');
|
|
@@ -309,7 +309,11 @@ export abstract class AbstractCursor<
|
|
|
309
309
|
const message =
|
|
310
310
|
'Cursor returned a `null` document, but the cursor is not exhausted. Mapping documents to `null` is not supported in the cursor transform.';
|
|
311
311
|
|
|
312
|
-
|
|
312
|
+
try {
|
|
313
|
+
await cleanupCursor(this, { needsToEmitClosed: true });
|
|
314
|
+
} catch (error) {
|
|
315
|
+
squashError(error);
|
|
316
|
+
}
|
|
313
317
|
|
|
314
318
|
throw new MongoAPIError(message);
|
|
315
319
|
}
|
|
@@ -327,7 +331,11 @@ export abstract class AbstractCursor<
|
|
|
327
331
|
// Only close the cursor if it has not already been closed. This finally clause handles
|
|
328
332
|
// the case when a user would break out of a for await of loop early.
|
|
329
333
|
if (!this.closed) {
|
|
330
|
-
|
|
334
|
+
try {
|
|
335
|
+
await this.close();
|
|
336
|
+
} catch (error) {
|
|
337
|
+
squashError(error);
|
|
338
|
+
}
|
|
331
339
|
}
|
|
332
340
|
}
|
|
333
341
|
}
|
|
@@ -387,7 +395,7 @@ export abstract class AbstractCursor<
|
|
|
387
395
|
throw new MongoCursorExhaustedError();
|
|
388
396
|
}
|
|
389
397
|
|
|
390
|
-
return next(this, { blocking: true, transform: true });
|
|
398
|
+
return await next(this, { blocking: true, transform: true });
|
|
391
399
|
}
|
|
392
400
|
|
|
393
401
|
/**
|
|
@@ -398,7 +406,7 @@ export abstract class AbstractCursor<
|
|
|
398
406
|
throw new MongoCursorExhaustedError();
|
|
399
407
|
}
|
|
400
408
|
|
|
401
|
-
return next(this, { blocking: false, transform: true });
|
|
409
|
+
return await next(this, { blocking: false, transform: true });
|
|
402
410
|
}
|
|
403
411
|
|
|
404
412
|
/**
|
|
@@ -605,7 +613,8 @@ export abstract class AbstractCursor<
|
|
|
605
613
|
// We only want to end this session if we created it, and it hasn't ended yet
|
|
606
614
|
if (session.explicit === false) {
|
|
607
615
|
if (!session.hasEnded) {
|
|
608
|
-
|
|
616
|
+
// eslint-disable-next-line github/no-then
|
|
617
|
+
session.endSession().then(undefined, squashError);
|
|
609
618
|
}
|
|
610
619
|
this[kSession] = this.client.startSession({ owner: this, explicit: false });
|
|
611
620
|
}
|
|
@@ -629,7 +638,7 @@ export abstract class AbstractCursor<
|
|
|
629
638
|
batchSize
|
|
630
639
|
});
|
|
631
640
|
|
|
632
|
-
return executeOperation(this[kClient], getMoreOperation);
|
|
641
|
+
return await executeOperation(this[kClient], getMoreOperation);
|
|
633
642
|
}
|
|
634
643
|
|
|
635
644
|
/**
|
|
@@ -724,9 +733,12 @@ async function next<T>(
|
|
|
724
733
|
try {
|
|
725
734
|
return cursor[kTransform](doc);
|
|
726
735
|
} catch (error) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
736
|
+
try {
|
|
737
|
+
await cleanupCursor(cursor, { error, needsToEmitClosed: true });
|
|
738
|
+
} catch (error) {
|
|
739
|
+
// `cleanupCursor` should never throw, squash and throw the original error
|
|
740
|
+
squashError(error);
|
|
741
|
+
}
|
|
730
742
|
throw error;
|
|
731
743
|
}
|
|
732
744
|
}
|
|
@@ -736,7 +748,7 @@ async function next<T>(
|
|
|
736
748
|
|
|
737
749
|
if (cursor.isDead) {
|
|
738
750
|
// if the cursor is dead, we clean it up
|
|
739
|
-
//
|
|
751
|
+
// cleanupCursor should never throw, but if it does it indicates a bug in the driver
|
|
740
752
|
// and we should surface the error
|
|
741
753
|
await cleanupCursor(cursor, {});
|
|
742
754
|
return null;
|
|
@@ -760,9 +772,12 @@ async function next<T>(
|
|
|
760
772
|
cursor[kId] = cursorId;
|
|
761
773
|
}
|
|
762
774
|
} catch (error) {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
775
|
+
try {
|
|
776
|
+
await cleanupCursor(cursor, { error, needsToEmitClosed: true });
|
|
777
|
+
} catch (error) {
|
|
778
|
+
// `cleanupCursor` should never throw, squash and throw the original error
|
|
779
|
+
squashError(error);
|
|
780
|
+
}
|
|
766
781
|
throw error;
|
|
767
782
|
}
|
|
768
783
|
|
|
@@ -802,7 +817,7 @@ async function cleanupCursor(
|
|
|
802
817
|
|
|
803
818
|
if (error) {
|
|
804
819
|
if (cursor.loadBalanced && error instanceof MongoNetworkError) {
|
|
805
|
-
return completeCleanup();
|
|
820
|
+
return await completeCleanup();
|
|
806
821
|
}
|
|
807
822
|
}
|
|
808
823
|
|
|
@@ -850,14 +865,16 @@ async function cleanupCursor(
|
|
|
850
865
|
cursor[kKilled] = true;
|
|
851
866
|
|
|
852
867
|
if (session.hasEnded) {
|
|
853
|
-
return completeCleanup();
|
|
868
|
+
return await completeCleanup();
|
|
854
869
|
}
|
|
855
870
|
|
|
856
871
|
try {
|
|
857
872
|
await executeOperation(
|
|
858
873
|
cursor[kClient],
|
|
859
874
|
new KillCursorsOperation(cursorId, cursorNs, server, { session })
|
|
860
|
-
)
|
|
875
|
+
);
|
|
876
|
+
} catch (error) {
|
|
877
|
+
squashError(error);
|
|
861
878
|
} finally {
|
|
862
879
|
await completeCleanup();
|
|
863
880
|
}
|
|
@@ -892,6 +909,7 @@ class ReadableCursorStream extends Readable {
|
|
|
892
909
|
}
|
|
893
910
|
|
|
894
911
|
override _destroy(error: Error | null, callback: (error?: Error | null) => void): void {
|
|
912
|
+
// eslint-disable-next-line github/no-then
|
|
895
913
|
this._cursor.close().then(
|
|
896
914
|
() => callback(error),
|
|
897
915
|
closeError => callback(closeError)
|
|
@@ -899,12 +917,14 @@ class ReadableCursorStream extends Readable {
|
|
|
899
917
|
}
|
|
900
918
|
|
|
901
919
|
private _readNext() {
|
|
920
|
+
// eslint-disable-next-line github/no-then
|
|
902
921
|
next(this._cursor, { blocking: true, transform: true }).then(
|
|
903
922
|
result => {
|
|
904
923
|
if (result == null) {
|
|
905
924
|
this.push(null);
|
|
906
925
|
} else if (this.destroyed) {
|
|
907
|
-
|
|
926
|
+
// eslint-disable-next-line github/no-then
|
|
927
|
+
this._cursor.close().then(undefined, squashError);
|
|
908
928
|
} else {
|
|
909
929
|
if (this.push(result)) {
|
|
910
930
|
return this._readNext();
|
|
@@ -919,7 +939,8 @@ class ReadableCursorStream extends Readable {
|
|
|
919
939
|
// a client during iteration. Alternatively, we could do the "right" thing and
|
|
920
940
|
// propagate the error message by removing this special case.
|
|
921
941
|
if (err.message.match(/server is closed/)) {
|
|
922
|
-
|
|
942
|
+
// eslint-disable-next-line github/no-then
|
|
943
|
+
this._cursor.close().then(undefined, squashError);
|
|
923
944
|
return this.push(null);
|
|
924
945
|
}
|
|
925
946
|
|
|
@@ -76,7 +76,7 @@ export class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
76
76
|
|
|
77
77
|
/** Execute the explain for the cursor */
|
|
78
78
|
async explain(verbosity?: ExplainVerbosityLike): Promise<Document> {
|
|
79
|
-
return executeOperation(
|
|
79
|
+
return await executeOperation(
|
|
80
80
|
this.client,
|
|
81
81
|
new AggregateOperation(this.namespace, this[kPipeline], {
|
|
82
82
|
...this[kOptions], // NOTE: order matters here, we may need to refine this
|
|
@@ -9,7 +9,7 @@ import { FindOperation, type FindOptions } from '../operations/find';
|
|
|
9
9
|
import type { Hint } from '../operations/operation';
|
|
10
10
|
import type { ClientSession } from '../sessions';
|
|
11
11
|
import { formatSort, type Sort, type SortDirection } from '../sort';
|
|
12
|
-
import { emitWarningOnce, mergeOptions, type MongoDBNamespace } from '../utils';
|
|
12
|
+
import { emitWarningOnce, mergeOptions, type MongoDBNamespace, squashError } from '../utils';
|
|
13
13
|
import { AbstractCursor, assertUninitialized } from './abstract_cursor';
|
|
14
14
|
|
|
15
15
|
/** @internal */
|
|
@@ -94,15 +94,19 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
94
94
|
limit && limit > 0 && numReturned + batchSize > limit ? limit - numReturned : batchSize;
|
|
95
95
|
|
|
96
96
|
if (batchSize <= 0) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
try {
|
|
98
|
+
await this.close();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
squashError(error);
|
|
101
|
+
// this is an optimization for the special case of a limit for a find command to avoid an
|
|
102
|
+
// extra getMore when the limit has been reached and the limit is a multiple of the batchSize.
|
|
103
|
+
// This is a consequence of the new query engine in 5.0 having no knowledge of the limit as it
|
|
104
|
+
// produces results for the find command. Once a batch is filled up, it is returned and only
|
|
105
|
+
// on the subsequent getMore will the query framework consider the limit, determine the cursor
|
|
106
|
+
// is exhausted and return a cursorId of zero.
|
|
107
|
+
// instead, if we determine there are no more documents to request from the server, we preemptively
|
|
108
|
+
// close the cursor
|
|
109
|
+
}
|
|
106
110
|
return { cursor: { id: Long.ZERO, nextBatch: [] } };
|
|
107
111
|
}
|
|
108
112
|
}
|
|
@@ -127,7 +131,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
127
131
|
if (typeof options === 'boolean') {
|
|
128
132
|
throw new MongoInvalidArgumentError('Invalid first parameter to count');
|
|
129
133
|
}
|
|
130
|
-
return executeOperation(
|
|
134
|
+
return await executeOperation(
|
|
131
135
|
this.client,
|
|
132
136
|
new CountOperation(this.namespace, this[kFilter], {
|
|
133
137
|
...this[kBuiltOptions], // NOTE: order matters here, we may need to refine this
|
|
@@ -139,7 +143,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
|
|
|
139
143
|
|
|
140
144
|
/** Execute the explain for the cursor */
|
|
141
145
|
async explain(verbosity?: ExplainVerbosityLike): Promise<Document> {
|
|
142
|
-
return executeOperation(
|
|
146
|
+
return await executeOperation(
|
|
143
147
|
this.client,
|
|
144
148
|
new FindOperation(undefined, this.namespace, this[kFilter], {
|
|
145
149
|
...this[kBuiltOptions], // NOTE: order matters here, we may need to refine this
|
package/src/db.ts
CHANGED
|
@@ -230,7 +230,7 @@ export class Db {
|
|
|
230
230
|
name: string,
|
|
231
231
|
options?: CreateCollectionOptions
|
|
232
232
|
): Promise<Collection<TSchema>> {
|
|
233
|
-
return executeOperation(
|
|
233
|
+
return await executeOperation(
|
|
234
234
|
this.client,
|
|
235
235
|
new CreateCollectionOperation(this, name, resolveOptions(this, options)) as TODO_NODE_3286
|
|
236
236
|
);
|
|
@@ -263,7 +263,7 @@ export class Db {
|
|
|
263
263
|
*/
|
|
264
264
|
async command(command: Document, options?: RunCommandOptions): Promise<Document> {
|
|
265
265
|
// Intentionally, we do not inherit options from parent for this operation.
|
|
266
|
-
return executeOperation(
|
|
266
|
+
return await executeOperation(
|
|
267
267
|
this.client,
|
|
268
268
|
new RunCommandOperation(this, command, {
|
|
269
269
|
...resolveBSONOptions(options),
|
|
@@ -320,7 +320,10 @@ export class Db {
|
|
|
320
320
|
* @param options - Optional settings for the command
|
|
321
321
|
*/
|
|
322
322
|
async stats(options?: DbStatsOptions): Promise<Document> {
|
|
323
|
-
return executeOperation(
|
|
323
|
+
return await executeOperation(
|
|
324
|
+
this.client,
|
|
325
|
+
new DbStatsOperation(this, resolveOptions(this, options))
|
|
326
|
+
);
|
|
324
327
|
}
|
|
325
328
|
|
|
326
329
|
/**
|
|
@@ -366,7 +369,7 @@ export class Db {
|
|
|
366
369
|
options?: RenameOptions
|
|
367
370
|
): Promise<Collection<TSchema>> {
|
|
368
371
|
// Intentionally, we do not inherit options from parent for this operation.
|
|
369
|
-
return executeOperation(
|
|
372
|
+
return await executeOperation(
|
|
370
373
|
this.client,
|
|
371
374
|
new RenameOperation(
|
|
372
375
|
this.collection<TSchema>(fromCollection) as TODO_NODE_3286,
|
|
@@ -383,7 +386,7 @@ export class Db {
|
|
|
383
386
|
* @param options - Optional settings for the command
|
|
384
387
|
*/
|
|
385
388
|
async dropCollection(name: string, options?: DropCollectionOptions): Promise<boolean> {
|
|
386
|
-
return executeOperation(
|
|
389
|
+
return await executeOperation(
|
|
387
390
|
this.client,
|
|
388
391
|
new DropCollectionOperation(this, name, resolveOptions(this, options))
|
|
389
392
|
);
|
|
@@ -395,7 +398,7 @@ export class Db {
|
|
|
395
398
|
* @param options - Optional settings for the command
|
|
396
399
|
*/
|
|
397
400
|
async dropDatabase(options?: DropDatabaseOptions): Promise<boolean> {
|
|
398
|
-
return executeOperation(
|
|
401
|
+
return await executeOperation(
|
|
399
402
|
this.client,
|
|
400
403
|
new DropDatabaseOperation(this, resolveOptions(this, options))
|
|
401
404
|
);
|
|
@@ -407,7 +410,7 @@ export class Db {
|
|
|
407
410
|
* @param options - Optional settings for the command
|
|
408
411
|
*/
|
|
409
412
|
async collections(options?: ListCollectionsOptions): Promise<Collection[]> {
|
|
410
|
-
return executeOperation(
|
|
413
|
+
return await executeOperation(
|
|
411
414
|
this.client,
|
|
412
415
|
new CollectionsOperation(this, resolveOptions(this, options))
|
|
413
416
|
);
|
|
@@ -439,7 +442,7 @@ export class Db {
|
|
|
439
442
|
* @param options - Optional settings for the command
|
|
440
443
|
*/
|
|
441
444
|
async removeUser(username: string, options?: RemoveUserOptions): Promise<boolean> {
|
|
442
|
-
return executeOperation(
|
|
445
|
+
return await executeOperation(
|
|
443
446
|
this.client,
|
|
444
447
|
new RemoveUserOperation(this, username, resolveOptions(this, options))
|
|
445
448
|
);
|
|
@@ -455,7 +458,7 @@ export class Db {
|
|
|
455
458
|
level: ProfilingLevel,
|
|
456
459
|
options?: SetProfilingLevelOptions
|
|
457
460
|
): Promise<ProfilingLevel> {
|
|
458
|
-
return executeOperation(
|
|
461
|
+
return await executeOperation(
|
|
459
462
|
this.client,
|
|
460
463
|
new SetProfilingLevelOperation(this, level, resolveOptions(this, options))
|
|
461
464
|
);
|
|
@@ -467,7 +470,7 @@ export class Db {
|
|
|
467
470
|
* @param options - Optional settings for the command
|
|
468
471
|
*/
|
|
469
472
|
async profilingLevel(options?: ProfilingLevelOptions): Promise<string> {
|
|
470
|
-
return executeOperation(
|
|
473
|
+
return await executeOperation(
|
|
471
474
|
this.client,
|
|
472
475
|
new ProfilingLevelOperation(this, resolveOptions(this, options))
|
|
473
476
|
);
|
|
@@ -480,7 +483,7 @@ export class Db {
|
|
|
480
483
|
* @param options - Optional settings for the command
|
|
481
484
|
*/
|
|
482
485
|
async indexInformation(name: string, options?: IndexInformationOptions): Promise<Document> {
|
|
483
|
-
return this.collection(name).indexInformation(resolveOptions(this, options));
|
|
486
|
+
return await this.collection(name).indexInformation(resolveOptions(this, options));
|
|
484
487
|
}
|
|
485
488
|
|
|
486
489
|
/**
|
package/src/encrypter.ts
CHANGED
|
@@ -108,13 +108,18 @@ export class Encrypter {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
async close(client: MongoClient, force: boolean): Promise<void> {
|
|
111
|
-
|
|
111
|
+
let error;
|
|
112
|
+
try {
|
|
113
|
+
await this.autoEncrypter.teardown(force);
|
|
114
|
+
} catch (autoEncrypterError) {
|
|
115
|
+
error = autoEncrypterError;
|
|
116
|
+
}
|
|
112
117
|
const internalClient = this[kInternalClient];
|
|
113
118
|
if (internalClient != null && client !== internalClient) {
|
|
114
|
-
return internalClient.close(force);
|
|
119
|
+
return await internalClient.close(force);
|
|
115
120
|
}
|
|
116
|
-
if (
|
|
117
|
-
throw
|
|
121
|
+
if (error != null) {
|
|
122
|
+
throw error;
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
|
package/src/gridfs/download.ts
CHANGED
|
@@ -183,24 +183,13 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
183
183
|
if (!stream.s.cursor) return;
|
|
184
184
|
if (!stream.s.file) return;
|
|
185
185
|
|
|
186
|
-
const handleReadResult = ({
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}: { error: Error; doc: null } | { error: null; doc: any }) => {
|
|
190
|
-
if (stream.destroyed) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (error) {
|
|
194
|
-
stream.destroy(error);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
186
|
+
const handleReadResult = (doc: Document | null) => {
|
|
187
|
+
if (stream.destroyed) return;
|
|
188
|
+
|
|
197
189
|
if (!doc) {
|
|
198
190
|
stream.push(null);
|
|
199
|
-
|
|
200
|
-
stream.s.cursor?.close().then(
|
|
201
|
-
() => null,
|
|
202
|
-
error => stream.destroy(error)
|
|
203
|
-
);
|
|
191
|
+
// eslint-disable-next-line github/no-then
|
|
192
|
+
stream.s.cursor?.close().then(undefined, error => stream.destroy(error));
|
|
204
193
|
return;
|
|
205
194
|
}
|
|
206
195
|
|
|
@@ -271,10 +260,11 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
271
260
|
return;
|
|
272
261
|
};
|
|
273
262
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
263
|
+
// eslint-disable-next-line github/no-then
|
|
264
|
+
stream.s.cursor.next().then(handleReadResult, error => {
|
|
265
|
+
if (stream.destroyed) return;
|
|
266
|
+
stream.destroy(error);
|
|
267
|
+
});
|
|
278
268
|
}
|
|
279
269
|
|
|
280
270
|
function init(stream: GridFSBucketReadStream): void {
|
|
@@ -289,13 +279,8 @@ function init(stream: GridFSBucketReadStream): void {
|
|
|
289
279
|
findOneOptions.skip = stream.s.options.skip;
|
|
290
280
|
}
|
|
291
281
|
|
|
292
|
-
const handleReadResult = ({
|
|
293
|
-
|
|
294
|
-
doc
|
|
295
|
-
}: { error: Error; doc: null } | { error: null; doc: any }) => {
|
|
296
|
-
if (error) {
|
|
297
|
-
return stream.destroy(error);
|
|
298
|
-
}
|
|
282
|
+
const handleReadResult = (doc: Document | null) => {
|
|
283
|
+
if (stream.destroyed) return;
|
|
299
284
|
|
|
300
285
|
if (!doc) {
|
|
301
286
|
const identifier = stream.s.filter._id
|
|
@@ -359,10 +344,11 @@ function init(stream: GridFSBucketReadStream): void {
|
|
|
359
344
|
return;
|
|
360
345
|
};
|
|
361
346
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
347
|
+
// eslint-disable-next-line github/no-then
|
|
348
|
+
stream.s.files.findOne(stream.s.filter, findOneOptions).then(handleReadResult, error => {
|
|
349
|
+
if (stream.destroyed) return;
|
|
350
|
+
stream.destroy(error);
|
|
351
|
+
});
|
|
366
352
|
}
|
|
367
353
|
|
|
368
354
|
function waitForFile(stream: GridFSBucketReadStream, callback: Callback): void {
|
package/src/gridfs/upload.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Document } from '../bson';
|
|
|
4
4
|
import { ObjectId } from '../bson';
|
|
5
5
|
import type { Collection } from '../collection';
|
|
6
6
|
import { MongoAPIError, MONGODB_ERROR_CODES, MongoError } from '../error';
|
|
7
|
-
import type
|
|
7
|
+
import { type Callback, squashError } from '../utils';
|
|
8
8
|
import type { WriteConcernOptions } from '../write_concern';
|
|
9
9
|
import { WriteConcern } from './../write_concern';
|
|
10
10
|
import type { GridFSFile } from './download';
|
|
@@ -133,13 +133,11 @@ export class GridFSBucketWriteStream extends Writable {
|
|
|
133
133
|
if (!this.bucket.s.calledOpenUploadStream) {
|
|
134
134
|
this.bucket.s.calledOpenUploadStream = true;
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
() => null
|
|
142
|
-
);
|
|
136
|
+
// eslint-disable-next-line github/no-then
|
|
137
|
+
checkIndexes(this).then(() => {
|
|
138
|
+
this.bucket.s.checkedIndexes = true;
|
|
139
|
+
this.bucket.emit('index');
|
|
140
|
+
}, squashError);
|
|
143
141
|
}
|
|
144
142
|
}
|
|
145
143
|
|
|
@@ -272,6 +270,7 @@ function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void {
|
|
|
272
270
|
return;
|
|
273
271
|
}
|
|
274
272
|
|
|
273
|
+
// eslint-disable-next-line github/no-then
|
|
275
274
|
stream.files.insertOne(gridFSFile, { writeConcern: stream.writeConcern }).then(
|
|
276
275
|
() => {
|
|
277
276
|
stream.gridFSFile = gridFSFile;
|
|
@@ -395,6 +394,7 @@ function doWrite(
|
|
|
395
394
|
return;
|
|
396
395
|
}
|
|
397
396
|
|
|
397
|
+
// eslint-disable-next-line github/no-then
|
|
398
398
|
stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(
|
|
399
399
|
() => {
|
|
400
400
|
--stream.state.outstandingRequests;
|
|
@@ -435,6 +435,7 @@ function writeRemnant(stream: GridFSBucketWriteStream, callback: Callback): void
|
|
|
435
435
|
return;
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
+
// eslint-disable-next-line github/no-then
|
|
438
439
|
stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(
|
|
439
440
|
() => {
|
|
440
441
|
--stream.state.outstandingRequests;
|
package/src/mongo_client.ts
CHANGED
|
@@ -49,7 +49,8 @@ import {
|
|
|
49
49
|
isHostMatch,
|
|
50
50
|
type MongoDBNamespace,
|
|
51
51
|
ns,
|
|
52
|
-
resolveOptions
|
|
52
|
+
resolveOptions,
|
|
53
|
+
squashError
|
|
53
54
|
} from './utils';
|
|
54
55
|
import type { W, WriteConcern, WriteConcernSettings } from './write_concern';
|
|
55
56
|
|
|
@@ -468,7 +469,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
468
469
|
*/
|
|
469
470
|
async connect(): Promise<this> {
|
|
470
471
|
if (this.connectionLock) {
|
|
471
|
-
return this.connectionLock;
|
|
472
|
+
return await this.connectionLock;
|
|
472
473
|
}
|
|
473
474
|
|
|
474
475
|
try {
|
|
@@ -599,13 +600,17 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
599
600
|
if (servers.length !== 0) {
|
|
600
601
|
const endSessions = Array.from(this.s.sessionPool.sessions, ({ id }) => id);
|
|
601
602
|
if (endSessions.length !== 0) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
603
|
+
try {
|
|
604
|
+
await executeOperation(
|
|
605
|
+
this,
|
|
606
|
+
new RunAdminCommandOperation(
|
|
607
|
+
{ endSessions },
|
|
608
|
+
{ readPreference: ReadPreference.primaryPreferred, noResponse: true }
|
|
609
|
+
)
|
|
610
|
+
);
|
|
611
|
+
} catch (error) {
|
|
612
|
+
squashError(error);
|
|
613
|
+
}
|
|
609
614
|
}
|
|
610
615
|
}
|
|
611
616
|
|
|
@@ -655,7 +660,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
655
660
|
*/
|
|
656
661
|
static async connect(url: string, options?: MongoClientOptions): Promise<MongoClient> {
|
|
657
662
|
const client = new this(url, options);
|
|
658
|
-
return client.connect();
|
|
663
|
+
return await client.connect();
|
|
659
664
|
}
|
|
660
665
|
|
|
661
666
|
/**
|
|
@@ -717,8 +722,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
717
722
|
} finally {
|
|
718
723
|
try {
|
|
719
724
|
await session.endSession();
|
|
720
|
-
} catch {
|
|
721
|
-
|
|
725
|
+
} catch (error) {
|
|
726
|
+
squashError(error);
|
|
722
727
|
}
|
|
723
728
|
}
|
|
724
729
|
}
|
package/src/mongo_logger.ts
CHANGED
|
@@ -836,7 +836,9 @@ export class MongoLogger {
|
|
|
836
836
|
|
|
837
837
|
if (isPromiseLike(this.pendingLog)) {
|
|
838
838
|
this.pendingLog = this.pendingLog
|
|
839
|
+
// eslint-disable-next-line github/no-then
|
|
839
840
|
.then(() => this.logDestination.write(logMessage))
|
|
841
|
+
// eslint-disable-next-line github/no-then
|
|
840
842
|
.then(this.clearPendingLog.bind(this), this.logWriteFailureHandler.bind(this));
|
|
841
843
|
return;
|
|
842
844
|
}
|
|
@@ -844,6 +846,7 @@ export class MongoLogger {
|
|
|
844
846
|
try {
|
|
845
847
|
const logResult = this.logDestination.write(logMessage);
|
|
846
848
|
if (isPromiseLike(logResult)) {
|
|
849
|
+
// eslint-disable-next-line github/no-then
|
|
847
850
|
this.pendingLog = logResult.then(
|
|
848
851
|
this.clearPendingLog.bind(this),
|
|
849
852
|
this.logWriteFailureHandler.bind(this)
|
|
@@ -134,7 +134,8 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
134
134
|
command.cursor.batchSize = options.batchSize;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
const res: TODO_NODE_3286 = await super.executeCommand(server, session, command);
|
|
138
|
+
return res;
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
|
package/src/operations/delete.ts
CHANGED
|
@@ -95,7 +95,8 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
const res: TODO_NODE_3286 = await super.executeCommand(server, session, command);
|
|
99
|
+
return res;
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
|
|
@@ -108,7 +109,7 @@ export class DeleteOneOperation extends DeleteOperation {
|
|
|
108
109
|
server: Server,
|
|
109
110
|
session: ClientSession | undefined
|
|
110
111
|
): Promise<DeleteResult> {
|
|
111
|
-
const res =
|
|
112
|
+
const res: TODO_NODE_3286 = await super.execute(server, session);
|
|
112
113
|
if (this.explain) return res;
|
|
113
114
|
if (res.code) throw new MongoServerError(res);
|
|
114
115
|
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
@@ -128,7 +129,7 @@ export class DeleteManyOperation extends DeleteOperation {
|
|
|
128
129
|
server: Server,
|
|
129
130
|
session: ClientSession | undefined
|
|
130
131
|
): Promise<DeleteResult> {
|
|
131
|
-
const res =
|
|
132
|
+
const res: TODO_NODE_3286 = await super.execute(server, session);
|
|
132
133
|
if (this.explain) return res;
|
|
133
134
|
if (res.code) throw new MongoServerError(res);
|
|
134
135
|
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
package/src/operations/drop.ts
CHANGED
|
@@ -69,7 +69,7 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
return this.executeWithoutEncryptedFieldsCheck(server, session);
|
|
72
|
+
return await this.executeWithoutEncryptedFieldsCheck(server, session);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
private async executeWithoutEncryptedFieldsCheck(
|