mongodb 4.2.0 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/README.md +2 -2
  2. package/lib/admin.js +3 -3
  3. package/lib/admin.js.map +1 -1
  4. package/lib/bson.js +16 -14
  5. package/lib/bson.js.map +1 -1
  6. package/lib/bulk/common.js +7 -7
  7. package/lib/bulk/common.js.map +1 -1
  8. package/lib/bulk/ordered.js +1 -1
  9. package/lib/bulk/ordered.js.map +1 -1
  10. package/lib/bulk/unordered.js +1 -1
  11. package/lib/bulk/unordered.js.map +1 -1
  12. package/lib/change_stream.js +6 -7
  13. package/lib/change_stream.js.map +1 -1
  14. package/lib/cmap/auth/auth_provider.js.map +1 -1
  15. package/lib/cmap/auth/gssapi.js +3 -3
  16. package/lib/cmap/auth/gssapi.js.map +1 -1
  17. package/lib/cmap/auth/mongo_credentials.js +24 -26
  18. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  19. package/lib/cmap/auth/mongocr.js +2 -2
  20. package/lib/cmap/auth/mongocr.js.map +1 -1
  21. package/lib/cmap/auth/mongodb_aws.js +6 -6
  22. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  23. package/lib/cmap/auth/plain.js +1 -1
  24. package/lib/cmap/auth/plain.js.map +1 -1
  25. package/lib/cmap/auth/providers.js +21 -0
  26. package/lib/cmap/auth/providers.js.map +1 -0
  27. package/lib/cmap/auth/scram.js +4 -4
  28. package/lib/cmap/auth/scram.js.map +1 -1
  29. package/lib/cmap/auth/x509.js +1 -1
  30. package/lib/cmap/auth/x509.js.map +1 -1
  31. package/lib/cmap/command_monitoring_events.js +3 -2
  32. package/lib/cmap/command_monitoring_events.js.map +1 -1
  33. package/lib/cmap/commands.js +20 -11
  34. package/lib/cmap/commands.js.map +1 -1
  35. package/lib/cmap/connect.js +119 -31
  36. package/lib/cmap/connect.js.map +1 -1
  37. package/lib/cmap/connection.js +36 -35
  38. package/lib/cmap/connection.js.map +1 -1
  39. package/lib/cmap/connection_pool.js +19 -30
  40. package/lib/cmap/connection_pool.js.map +1 -1
  41. package/lib/cmap/message_stream.js +3 -3
  42. package/lib/cmap/message_stream.js.map +1 -1
  43. package/lib/cmap/stream_description.js +4 -4
  44. package/lib/cmap/stream_description.js.map +1 -1
  45. package/lib/cmap/wire_protocol/compression.js +2 -1
  46. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  47. package/lib/cmap/wire_protocol/shared.js +4 -3
  48. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  49. package/lib/collection.js +45 -47
  50. package/lib/collection.js.map +1 -1
  51. package/lib/connection_string.js +48 -23
  52. package/lib/connection_string.js.map +1 -1
  53. package/lib/constants.js +113 -1
  54. package/lib/constants.js.map +1 -1
  55. package/lib/cursor/abstract_cursor.js +10 -7
  56. package/lib/cursor/abstract_cursor.js.map +1 -1
  57. package/lib/cursor/aggregation_cursor.js +1 -1
  58. package/lib/cursor/aggregation_cursor.js.map +1 -1
  59. package/lib/cursor/find_cursor.js +1 -1
  60. package/lib/cursor/find_cursor.js.map +1 -1
  61. package/lib/db.js +23 -13
  62. package/lib/db.js.map +1 -1
  63. package/lib/deps.js +0 -1
  64. package/lib/deps.js.map +1 -1
  65. package/lib/encrypter.js +12 -4
  66. package/lib/encrypter.js.map +1 -1
  67. package/lib/error.js +47 -24
  68. package/lib/error.js.map +1 -1
  69. package/lib/gridfs/download.js +1 -1
  70. package/lib/gridfs/download.js.map +1 -1
  71. package/lib/gridfs/index.js +3 -3
  72. package/lib/gridfs/index.js.map +1 -1
  73. package/lib/gridfs/upload.js +3 -2
  74. package/lib/gridfs/upload.js.map +1 -1
  75. package/lib/index.js +81 -81
  76. package/lib/index.js.map +1 -1
  77. package/lib/logger.js +1 -1
  78. package/lib/logger.js.map +1 -1
  79. package/lib/mongo_client.js +5 -5
  80. package/lib/mongo_client.js.map +1 -1
  81. package/lib/mongo_types.js.map +1 -1
  82. package/lib/operations/add_user.js +3 -3
  83. package/lib/operations/add_user.js.map +1 -1
  84. package/lib/operations/aggregate.js +1 -1
  85. package/lib/operations/aggregate.js.map +1 -1
  86. package/lib/operations/bulk_write.js.map +1 -1
  87. package/lib/operations/collections.js +1 -1
  88. package/lib/operations/collections.js.map +1 -1
  89. package/lib/operations/command.js +5 -6
  90. package/lib/operations/command.js.map +1 -1
  91. package/lib/operations/common_functions.js.map +1 -1
  92. package/lib/operations/connect.js +4 -13
  93. package/lib/operations/connect.js.map +1 -1
  94. package/lib/operations/count.js +1 -1
  95. package/lib/operations/count.js.map +1 -1
  96. package/lib/operations/count_documents.js.map +1 -1
  97. package/lib/operations/create_collection.js +3 -2
  98. package/lib/operations/create_collection.js.map +1 -1
  99. package/lib/operations/delete.js +3 -3
  100. package/lib/operations/delete.js.map +1 -1
  101. package/lib/operations/distinct.js +3 -3
  102. package/lib/operations/distinct.js.map +1 -1
  103. package/lib/operations/drop.js +1 -1
  104. package/lib/operations/drop.js.map +1 -1
  105. package/lib/operations/estimated_document_count.js +2 -2
  106. package/lib/operations/estimated_document_count.js.map +1 -1
  107. package/lib/operations/eval.js +2 -2
  108. package/lib/operations/eval.js.map +1 -1
  109. package/lib/operations/execute_operation.js +15 -9
  110. package/lib/operations/execute_operation.js.map +1 -1
  111. package/lib/operations/find.js +5 -5
  112. package/lib/operations/find.js.map +1 -1
  113. package/lib/operations/find_and_modify.js +2 -2
  114. package/lib/operations/find_and_modify.js.map +1 -1
  115. package/lib/operations/get_more.js +28 -0
  116. package/lib/operations/get_more.js.map +1 -0
  117. package/lib/operations/indexes.js +4 -4
  118. package/lib/operations/indexes.js.map +1 -1
  119. package/lib/operations/insert.js +3 -3
  120. package/lib/operations/insert.js.map +1 -1
  121. package/lib/operations/is_capped.js +1 -1
  122. package/lib/operations/is_capped.js.map +1 -1
  123. package/lib/operations/list_collections.js +3 -3
  124. package/lib/operations/list_collections.js.map +1 -1
  125. package/lib/operations/list_databases.js +1 -1
  126. package/lib/operations/list_databases.js.map +1 -1
  127. package/lib/operations/map_reduce.js +4 -3
  128. package/lib/operations/map_reduce.js.map +1 -1
  129. package/lib/operations/operation.js +3 -2
  130. package/lib/operations/operation.js.map +1 -1
  131. package/lib/operations/options_operation.js +1 -1
  132. package/lib/operations/options_operation.js.map +1 -1
  133. package/lib/operations/profiling_level.js +1 -1
  134. package/lib/operations/profiling_level.js.map +1 -1
  135. package/lib/operations/remove_user.js +1 -1
  136. package/lib/operations/remove_user.js.map +1 -1
  137. package/lib/operations/rename.js +3 -3
  138. package/lib/operations/rename.js.map +1 -1
  139. package/lib/operations/run_command.js +1 -1
  140. package/lib/operations/run_command.js.map +1 -1
  141. package/lib/operations/set_profiling_level.js +2 -2
  142. package/lib/operations/set_profiling_level.js.map +1 -1
  143. package/lib/operations/stats.js +1 -1
  144. package/lib/operations/stats.js.map +1 -1
  145. package/lib/operations/update.js +2 -2
  146. package/lib/operations/update.js.map +1 -1
  147. package/lib/operations/validate_collection.js +1 -1
  148. package/lib/operations/validate_collection.js.map +1 -1
  149. package/lib/read_preference.js +15 -5
  150. package/lib/read_preference.js.map +1 -1
  151. package/lib/sdam/events.js +4 -4
  152. package/lib/sdam/monitor.js +19 -18
  153. package/lib/sdam/monitor.js.map +1 -1
  154. package/lib/sdam/server.js +24 -31
  155. package/lib/sdam/server.js.map +1 -1
  156. package/lib/sdam/server_description.js +38 -38
  157. package/lib/sdam/server_description.js.map +1 -1
  158. package/lib/sdam/server_selection.js +19 -3
  159. package/lib/sdam/server_selection.js.map +1 -1
  160. package/lib/sdam/srv_polling.js +2 -2
  161. package/lib/sdam/srv_polling.js.map +1 -1
  162. package/lib/sdam/topology.js +32 -62
  163. package/lib/sdam/topology.js.map +1 -1
  164. package/lib/sdam/topology_description.js +3 -3
  165. package/lib/sdam/topology_description.js.map +1 -1
  166. package/lib/sessions.js +13 -28
  167. package/lib/sessions.js.map +1 -1
  168. package/lib/transactions.js +1 -1
  169. package/lib/transactions.js.map +1 -1
  170. package/lib/utils.js +46 -15
  171. package/lib/utils.js.map +1 -1
  172. package/mongodb.d.ts +145 -61
  173. package/mongodb.ts34.d.ts +173 -60
  174. package/package.json +29 -28
  175. package/src/admin.ts +9 -9
  176. package/src/bson.ts +26 -17
  177. package/src/bulk/common.ts +22 -23
  178. package/src/bulk/ordered.ts +4 -4
  179. package/src/bulk/unordered.ts +5 -5
  180. package/src/change_stream.ts +31 -28
  181. package/src/cmap/auth/auth_provider.ts +3 -3
  182. package/src/cmap/auth/gssapi.ts +8 -8
  183. package/src/cmap/auth/mongo_credentials.ts +11 -15
  184. package/src/cmap/auth/mongocr.ts +3 -2
  185. package/src/cmap/auth/mongodb_aws.ts +10 -11
  186. package/src/cmap/auth/plain.ts +1 -1
  187. package/src/cmap/auth/providers.ts +21 -0
  188. package/src/cmap/auth/scram.ts +9 -9
  189. package/src/cmap/auth/x509.ts +3 -3
  190. package/src/cmap/command_monitoring_events.ts +4 -3
  191. package/src/cmap/commands.ts +30 -19
  192. package/src/cmap/connect.ts +161 -37
  193. package/src/cmap/connection.ts +83 -63
  194. package/src/cmap/connection_pool.ts +39 -39
  195. package/src/cmap/connection_pool_events.ts +1 -1
  196. package/src/cmap/message_stream.ts +9 -8
  197. package/src/cmap/stream_description.ts +5 -5
  198. package/src/cmap/wire_protocol/compression.ts +4 -3
  199. package/src/cmap/wire_protocol/shared.ts +10 -9
  200. package/src/collection.ts +114 -95
  201. package/src/connection_string.ts +66 -29
  202. package/src/constants.ts +122 -0
  203. package/src/cursor/abstract_cursor.ts +21 -22
  204. package/src/cursor/aggregation_cursor.ts +6 -6
  205. package/src/cursor/find_cursor.ts +2 -2
  206. package/src/db.ts +44 -33
  207. package/src/deps.ts +3 -1
  208. package/src/encrypter.ts +12 -3
  209. package/src/error.ts +52 -24
  210. package/src/gridfs/download.ts +10 -8
  211. package/src/gridfs/index.ts +11 -11
  212. package/src/gridfs/upload.ts +13 -10
  213. package/src/index.ts +204 -199
  214. package/src/logger.ts +2 -1
  215. package/src/mongo_client.ts +46 -32
  216. package/src/mongo_types.ts +119 -21
  217. package/src/operations/add_user.ts +7 -6
  218. package/src/operations/aggregate.ts +5 -5
  219. package/src/operations/bulk_write.ts +5 -5
  220. package/src/operations/collections.ts +2 -2
  221. package/src/operations/command.ts +15 -9
  222. package/src/operations/common_functions.ts +4 -4
  223. package/src/operations/connect.ts +4 -14
  224. package/src/operations/count.ts +4 -4
  225. package/src/operations/count_documents.ts +3 -3
  226. package/src/operations/create_collection.ts +7 -6
  227. package/src/operations/delete.ts +5 -5
  228. package/src/operations/distinct.ts +4 -4
  229. package/src/operations/drop.ts +4 -4
  230. package/src/operations/estimated_document_count.ts +5 -5
  231. package/src/operations/eval.ts +5 -5
  232. package/src/operations/execute_operation.ts +21 -13
  233. package/src/operations/find.ts +14 -14
  234. package/src/operations/find_and_modify.ts +7 -7
  235. package/src/operations/get_more.ts +49 -0
  236. package/src/operations/indexes.ts +16 -16
  237. package/src/operations/insert.ts +9 -9
  238. package/src/operations/is_capped.ts +3 -3
  239. package/src/operations/list_collections.ts +6 -6
  240. package/src/operations/list_databases.ts +4 -4
  241. package/src/operations/map_reduce.ts +10 -9
  242. package/src/operations/operation.ts +5 -4
  243. package/src/operations/options_operation.ts +3 -3
  244. package/src/operations/profiling_level.ts +4 -4
  245. package/src/operations/remove_user.ts +4 -4
  246. package/src/operations/rename.ts +6 -6
  247. package/src/operations/run_command.ts +3 -3
  248. package/src/operations/set_profiling_level.ts +6 -5
  249. package/src/operations/stats.ts +4 -4
  250. package/src/operations/update.ts +10 -10
  251. package/src/operations/validate_collection.ts +4 -4
  252. package/src/read_preference.ts +18 -7
  253. package/src/sdam/common.ts +2 -2
  254. package/src/sdam/events.ts +5 -5
  255. package/src/sdam/monitor.ts +29 -32
  256. package/src/sdam/server.ts +64 -62
  257. package/src/sdam/server_description.ts +41 -48
  258. package/src/sdam/server_selection.ts +21 -3
  259. package/src/sdam/srv_polling.ts +3 -2
  260. package/src/sdam/topology.ts +71 -89
  261. package/src/sdam/topology_description.ts +5 -5
  262. package/src/sessions.ts +31 -48
  263. package/src/transactions.ts +4 -4
  264. package/src/utils.ts +69 -33
  265. package/lib/cmap/auth/defaultAuthProviders.js +0 -30
  266. package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
  267. package/src/cmap/auth/defaultAuthProviders.ts +0 -32
@@ -1,20 +1,20 @@
1
- import { Aspect, defineAspects, Hint } from './operation';
2
- import {
3
- maxWireVersion,
4
- MongoDBNamespace,
5
- Callback,
6
- normalizeHintField,
7
- decorateWithExplain
8
- } from '../utils';
9
- import { MongoInvalidArgumentError, MongoCompatibilityError } from '../error';
10
1
  import type { Document } from '../bson';
11
- import type { Server } from '../sdam/server';
12
- import type { Collection } from '../collection';
13
- import { CommandOperation, CommandOperationOptions, CollationOptions } from './command';
14
- import { Sort, formatSort } from '../sort';
15
2
  import { isSharded } from '../cmap/wire_protocol/shared';
3
+ import type { Collection } from '../collection';
4
+ import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
16
5
  import { ReadConcern } from '../read_concern';
6
+ import type { Server } from '../sdam/server';
17
7
  import type { ClientSession } from '../sessions';
8
+ import { formatSort, Sort } from '../sort';
9
+ import {
10
+ Callback,
11
+ decorateWithExplain,
12
+ maxWireVersion,
13
+ MongoDBNamespace,
14
+ normalizeHintField
15
+ } from '../utils';
16
+ import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
17
+ import { Aspect, defineAspects, Hint } from './operation';
18
18
 
19
19
  /**
20
20
  * @public
@@ -36,7 +36,7 @@ export interface FindOptions<TSchema extends Document = Document> extends Comman
36
36
  timeout?: boolean;
37
37
  /** Specify if the cursor is tailable. */
38
38
  tailable?: boolean;
39
- /** Specify if the cursor is a a tailable-await cursor. Requires `tailable` to be true */
39
+ /** Specify if the cursor is a tailable-await cursor. Requires `tailable` to be true */
40
40
  awaitData?: boolean;
41
41
  /** Set the batchSize for the getMoreCommand when iterating over the query results. */
42
42
  batchSize?: number;
@@ -1,14 +1,14 @@
1
- import { ReadPreference } from '../read_preference';
2
- import { maxWireVersion, decorateWithCollation, hasAtomicOperators, Callback } from '../utils';
3
- import { MongoInvalidArgumentError, MongoCompatibilityError } from '../error';
4
- import { CommandOperation, CommandOperationOptions } from './command';
5
- import { defineAspects, Aspect } from './operation';
6
1
  import type { Document } from '../bson';
7
- import type { Server } from '../sdam/server';
8
2
  import type { Collection } from '../collection';
9
- import { Sort, SortForCmd, formatSort } from '../sort';
3
+ import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
4
+ import { ReadPreference } from '../read_preference';
5
+ import type { Server } from '../sdam/server';
10
6
  import type { ClientSession } from '../sessions';
7
+ import { formatSort, Sort, SortForCmd } from '../sort';
8
+ import { Callback, decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils';
11
9
  import type { WriteConcern, WriteConcernSettings } from '../write_concern';
10
+ import { CommandOperation, CommandOperationOptions } from './command';
11
+ import { Aspect, defineAspects } from './operation';
12
12
 
13
13
  /** @public */
14
14
  export const ReturnDocument = Object.freeze({
@@ -0,0 +1,49 @@
1
+ import type { Document, Long } from '../bson';
2
+ import { MongoRuntimeError } from '../error';
3
+ import type { Server } from '../sdam/server';
4
+ import type { ClientSession } from '../sessions';
5
+ import type { Callback, MongoDBNamespace } from '../utils';
6
+ import { AbstractOperation, Aspect, defineAspects, OperationOptions } from './operation';
7
+
8
+ /**
9
+ * @public
10
+ */
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ export interface GetMoreOptions extends OperationOptions {
13
+ /** Set the batchSize for the getMoreCommand when iterating over the query results. */
14
+ batchSize?: number;
15
+ /** You can put a $comment field on a query to make looking in the profiler logs simpler. */
16
+ comment?: string | Document;
17
+ /** Number of milliseconds to wait before aborting the query. */
18
+ maxTimeMS?: number;
19
+ }
20
+
21
+ /** @internal */
22
+ export class GetMoreOperation extends AbstractOperation {
23
+ cursorId: Long;
24
+ options: GetMoreOptions;
25
+ server: Server;
26
+
27
+ constructor(ns: MongoDBNamespace, cursorId: Long, server: Server, options: GetMoreOptions = {}) {
28
+ super(options);
29
+ this.options = options;
30
+ this.ns = ns;
31
+ this.cursorId = cursorId;
32
+ this.server = server;
33
+ }
34
+
35
+ /**
36
+ * Although there is a server already associated with the get more operation, the signature
37
+ * for execute passes a server so we will just use that one.
38
+ */
39
+ execute(server: Server, session: ClientSession, callback: Callback<Document>): void {
40
+ if (server !== this.server) {
41
+ return callback(
42
+ new MongoRuntimeError('Getmore must run on the same server operation began on')
43
+ );
44
+ }
45
+ server.getMore(this.ns, this.cursorId, this.options, callback);
46
+ }
47
+ }
48
+
49
+ defineAspects(GetMoreOperation, [Aspect.READ_OPERATION, Aspect.CURSOR_ITERATING]);
@@ -1,28 +1,28 @@
1
- import { indexInformation, IndexInformationOptions } from './common_functions';
2
- import { AbstractOperation, Aspect, defineAspects } from './operation';
3
- import { MONGODB_ERROR_CODES, MongoServerError, MongoCompatibilityError } from '../error';
1
+ import type { Document } from '../bson';
2
+ import type { Collection } from '../collection';
3
+ import { AbstractCursor } from '../cursor/abstract_cursor';
4
+ import type { Db } from '../db';
5
+ import { MongoCompatibilityError, MONGODB_ERROR_CODES, MongoServerError } from '../error';
6
+ import type { OneOrMore } from '../mongo_types';
7
+ import { ReadPreference } from '../read_preference';
8
+ import type { Server } from '../sdam/server';
9
+ import type { ClientSession } from '../sessions';
4
10
  import {
11
+ Callback,
12
+ getTopology,
5
13
  maxWireVersion,
6
- parseIndexOptions,
7
14
  MongoDBNamespace,
8
- Callback,
9
- getTopology
15
+ parseIndexOptions
10
16
  } from '../utils';
11
17
  import {
18
+ CollationOptions,
12
19
  CommandOperation,
13
20
  CommandOperationOptions,
14
- OperationParent,
15
- CollationOptions
21
+ OperationParent
16
22
  } from './command';
17
- import { ReadPreference } from '../read_preference';
18
- import type { Server } from '../sdam/server';
19
- import type { Document } from '../bson';
20
- import type { Collection } from '../collection';
21
- import type { Db } from '../db';
22
- import { AbstractCursor } from '../cursor/abstract_cursor';
23
- import type { ClientSession } from '../sessions';
23
+ import { indexInformation, IndexInformationOptions } from './common_functions';
24
24
  import { executeOperation, ExecutionResult } from './execute_operation';
25
- import type { OneOrMore } from '../mongo_types';
25
+ import { AbstractOperation, Aspect, defineAspects } from './operation';
26
26
 
27
27
  const LIST_INDEXES_WIRE_VERSION = 3;
28
28
  const VALID_INDEX_OPTIONS = new Set([
@@ -1,16 +1,16 @@
1
- import { MongoServerError, MongoInvalidArgumentError } from '../error';
2
- import { defineAspects, Aspect, AbstractOperation } from './operation';
3
- import { CommandOperation, CommandOperationOptions } from './command';
4
- import { prepareDocs } from './common_functions';
5
- import type { Callback, MongoDBNamespace } from '../utils';
6
- import type { Server } from '../sdam/server';
7
- import type { Collection } from '../collection';
8
1
  import type { Document } from '../bson';
9
2
  import type { BulkWriteOptions } from '../bulk/common';
10
- import { WriteConcern } from '../write_concern';
3
+ import type { Collection } from '../collection';
4
+ import { MongoInvalidArgumentError, MongoServerError } from '../error';
5
+ import type { InferIdType } from '../mongo_types';
6
+ import type { Server } from '../sdam/server';
11
7
  import type { ClientSession } from '../sessions';
8
+ import type { Callback, MongoDBNamespace } from '../utils';
9
+ import { WriteConcern } from '../write_concern';
12
10
  import { BulkWriteOperation } from './bulk_write';
13
- import type { InferIdType } from '../mongo_types';
11
+ import { CommandOperation, CommandOperationOptions } from './command';
12
+ import { prepareDocs } from './common_functions';
13
+ import { AbstractOperation, Aspect, defineAspects } from './operation';
14
14
 
15
15
  /** @internal */
16
16
  export class InsertOperation extends CommandOperation<Document> {
@@ -1,9 +1,9 @@
1
- import type { Callback } from '../utils';
2
1
  import type { Collection } from '../collection';
3
- import { OperationOptions, AbstractOperation } from './operation';
2
+ import { MongoAPIError } from '../error';
4
3
  import type { Server } from '../sdam/server';
5
4
  import type { ClientSession } from '../sessions';
6
- import { MongoAPIError } from '../error';
5
+ import type { Callback } from '../utils';
6
+ import { AbstractOperation, OperationOptions } from './operation';
7
7
 
8
8
  /** @internal */
9
9
  export class IsCappedOperation extends AbstractOperation<boolean> {
@@ -1,13 +1,13 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import { Aspect, defineAspects } from './operation';
3
- import { maxWireVersion, Callback, getTopology, MongoDBNamespace } from '../utils';
4
- import * as CONSTANTS from '../constants';
5
1
  import type { Binary, Document } from '../bson';
6
- import type { Server } from '../sdam/server';
7
- import type { Db } from '../db';
2
+ import * as CONSTANTS from '../constants';
8
3
  import { AbstractCursor } from '../cursor/abstract_cursor';
4
+ import type { Db } from '../db';
5
+ import type { Server } from '../sdam/server';
9
6
  import type { ClientSession } from '../sessions';
7
+ import { Callback, getTopology, maxWireVersion, MongoDBNamespace } from '../utils';
8
+ import { CommandOperation, CommandOperationOptions } from './command';
10
9
  import { executeOperation, ExecutionResult } from './execute_operation';
10
+ import { Aspect, defineAspects } from './operation';
11
11
 
12
12
  const LIST_COLLECTIONS_WIRE_VERSION = 3;
13
13
 
@@ -1,10 +1,10 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import { Aspect, defineAspects } from './operation';
3
- import { MongoDBNamespace, Callback } from '../utils';
4
1
  import type { Document } from '../bson';
5
- import type { Server } from '../sdam/server';
6
2
  import type { Db } from '../db';
3
+ import type { Server } from '../sdam/server';
7
4
  import type { ClientSession } from '../sessions';
5
+ import { Callback, MongoDBNamespace } from '../utils';
6
+ import { CommandOperation, CommandOperationOptions } from './command';
7
+ import { Aspect, defineAspects } from './operation';
8
8
 
9
9
  /** @public */
10
10
  export interface ListDatabasesResult {
@@ -1,22 +1,22 @@
1
+ import type { ObjectId } from '../bson';
1
2
  import { Code, Document } from '../bson';
3
+ import type { Collection } from '../collection';
4
+ import { Db } from '../db';
5
+ import { MongoCompatibilityError, MongoServerError } from '../error';
6
+ import { ReadPreference, ReadPreferenceMode } from '../read_preference';
7
+ import type { Server } from '../sdam/server';
8
+ import type { ClientSession } from '../sessions';
9
+ import type { Sort } from '../sort';
2
10
  import {
3
11
  applyWriteConcern,
12
+ Callback,
4
13
  decorateWithCollation,
5
14
  decorateWithReadConcern,
6
15
  isObject,
7
- Callback,
8
16
  maxWireVersion
9
17
  } from '../utils';
10
- import { ReadPreference, ReadPreferenceMode } from '../read_preference';
11
18
  import { CommandOperation, CommandOperationOptions } from './command';
12
- import type { Server } from '../sdam/server';
13
- import type { Collection } from '../collection';
14
- import type { Sort } from '../sort';
15
- import { MongoServerError, MongoCompatibilityError } from '../error';
16
- import type { ObjectId } from '../bson';
17
19
  import { Aspect, defineAspects } from './operation';
18
- import type { ClientSession } from '../sessions';
19
- import { Db } from '../db';
20
20
 
21
21
  const exclusionList = [
22
22
  'explain',
@@ -33,6 +33,7 @@ const exclusionList = [
33
33
  'bsonRegExp',
34
34
  'serializeFunctions',
35
35
  'ignoreUndefined',
36
+ 'enableUtf8Validation',
36
37
  'scope' // this option is reformatted thus exclude the original
37
38
  ];
38
39
 
@@ -1,8 +1,8 @@
1
+ import { BSONSerializeOptions, Document, resolveBSONOptions } from '../bson';
1
2
  import { ReadPreference, ReadPreferenceLike } from '../read_preference';
2
- import type { ClientSession } from '../sessions';
3
- import { Document, BSONSerializeOptions, resolveBSONOptions } from '../bson';
4
- import type { MongoDBNamespace, Callback } from '../utils';
5
3
  import type { Server } from '../sdam/server';
4
+ import type { ClientSession } from '../sessions';
5
+ import type { Callback, MongoDBNamespace } from '../utils';
6
6
 
7
7
  export const Aspect = {
8
8
  READ_OPERATION: Symbol('READ_OPERATION'),
@@ -10,7 +10,8 @@ export const Aspect = {
10
10
  RETRYABLE: Symbol('RETRYABLE'),
11
11
  EXPLAINABLE: Symbol('EXPLAINABLE'),
12
12
  SKIP_COLLATION: Symbol('SKIP_COLLATION'),
13
- CURSOR_CREATING: Symbol('CURSOR_CREATING')
13
+ CURSOR_CREATING: Symbol('CURSOR_CREATING'),
14
+ CURSOR_ITERATING: Symbol('CURSOR_ITERATING')
14
15
  } as const;
15
16
 
16
17
  /** @public */
@@ -1,10 +1,10 @@
1
- import { AbstractOperation, OperationOptions } from './operation';
2
- import { MongoAPIError } from '../error';
3
- import type { Callback } from '../utils';
4
1
  import type { Document } from '../bson';
5
2
  import type { Collection } from '../collection';
3
+ import { MongoAPIError } from '../error';
6
4
  import type { Server } from '../sdam/server';
7
5
  import type { ClientSession } from '../sessions';
6
+ import type { Callback } from '../utils';
7
+ import { AbstractOperation, OperationOptions } from './operation';
8
8
 
9
9
  /** @internal */
10
10
  export class OptionsOperation extends AbstractOperation<Document> {
@@ -1,9 +1,9 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import type { Callback } from '../utils';
3
- import type { Server } from '../sdam/server';
4
1
  import type { Db } from '../db';
5
- import type { ClientSession } from '../sessions';
6
2
  import { MongoRuntimeError } from '../error';
3
+ import type { Server } from '../sdam/server';
4
+ import type { ClientSession } from '../sessions';
5
+ import type { Callback } from '../utils';
6
+ import { CommandOperation, CommandOperationOptions } from './command';
7
7
 
8
8
  /** @public */
9
9
  export type ProfilingLevelOptions = CommandOperationOptions;
@@ -1,9 +1,9 @@
1
- import { Aspect, defineAspects } from './operation';
2
- import { CommandOperation, CommandOperationOptions } from './command';
3
- import type { Callback } from '../utils';
4
- import type { Server } from '../sdam/server';
5
1
  import type { Db } from '../db';
2
+ import type { Server } from '../sdam/server';
6
3
  import type { ClientSession } from '../sessions';
4
+ import type { Callback } from '../utils';
5
+ import { CommandOperation, CommandOperationOptions } from './command';
6
+ import { Aspect, defineAspects } from './operation';
7
7
 
8
8
  /** @public */
9
9
  export type RemoveUserOptions = CommandOperationOptions;
@@ -1,12 +1,12 @@
1
- import { checkCollectionName, Callback } from '../utils';
2
- import { RunAdminCommandOperation } from './run_command';
3
- import { defineAspects, Aspect } from './operation';
4
- import type { Server } from '../sdam/server';
1
+ import type { Document } from '../bson';
5
2
  import { Collection } from '../collection';
6
- import type { CommandOperationOptions } from './command';
7
3
  import { MongoServerError } from '../error';
4
+ import type { Server } from '../sdam/server';
8
5
  import type { ClientSession } from '../sessions';
9
- import type { Document } from 'bson';
6
+ import { Callback, checkCollectionName } from '../utils';
7
+ import type { CommandOperationOptions } from './command';
8
+ import { Aspect, defineAspects } from './operation';
9
+ import { RunAdminCommandOperation } from './run_command';
10
10
 
11
11
  /** @public */
12
12
  export interface RenameOptions extends CommandOperationOptions {
@@ -1,8 +1,8 @@
1
- import { CommandOperation, CommandOperationOptions, OperationParent } from './command';
2
- import { MongoDBNamespace, Callback } from '../utils';
3
- import type { Server } from '../sdam/server';
4
1
  import type { Document } from '../bson';
2
+ import type { Server } from '../sdam/server';
5
3
  import type { ClientSession } from '../sessions';
4
+ import { Callback, MongoDBNamespace } from '../utils';
5
+ import { CommandOperation, CommandOperationOptions, OperationParent } from './command';
6
6
 
7
7
  /** @public */
8
8
  export type RunCommandOptions = CommandOperationOptions;
@@ -1,10 +1,11 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import type { Callback } from '../utils';
3
- import { enumToString } from '../utils';
4
- import type { Server } from '../sdam/server';
5
1
  import type { Db } from '../db';
2
+ import { MongoInvalidArgumentError, MongoRuntimeError } from '../error';
3
+ import type { Server } from '../sdam/server';
6
4
  import type { ClientSession } from '../sessions';
7
- import { MongoRuntimeError, MongoInvalidArgumentError } from '../error';
5
+ import type { Callback } from '../utils';
6
+ import { enumToString } from '../utils';
7
+ import { CommandOperation, CommandOperationOptions } from './command';
8
+
8
9
  const levelValues = new Set(['off', 'slow_only', 'all']);
9
10
 
10
11
  /** @public */
@@ -1,11 +1,11 @@
1
- import { Aspect, defineAspects } from './operation';
2
- import { CommandOperation, CommandOperationOptions } from './command';
3
- import type { Callback } from '../utils';
4
1
  import type { Document } from '../bson';
5
- import type { Server } from '../sdam/server';
6
2
  import type { Collection } from '../collection';
7
3
  import type { Db } from '../db';
4
+ import type { Server } from '../sdam/server';
8
5
  import type { ClientSession } from '../sessions';
6
+ import type { Callback } from '../utils';
7
+ import { CommandOperation, CommandOperationOptions } from './command';
8
+ import { Aspect, defineAspects } from './operation';
9
9
 
10
10
  /** @public */
11
11
  export interface CollStatsOptions extends CommandOperationOptions {
@@ -1,17 +1,17 @@
1
- import { defineAspects, Aspect, Hint } from './operation';
1
+ import type { Document, ObjectId } from '../bson';
2
+ import type { Collection } from '../collection';
3
+ import { MongoCompatibilityError, MongoInvalidArgumentError, MongoServerError } from '../error';
4
+ import type { Server } from '../sdam/server';
5
+ import type { ClientSession } from '../sessions';
2
6
  import {
3
- hasAtomicOperators,
4
- MongoDBNamespace,
5
7
  Callback,
6
8
  collationNotSupported,
7
- maxWireVersion
9
+ hasAtomicOperators,
10
+ maxWireVersion,
11
+ MongoDBNamespace
8
12
  } from '../utils';
9
- import { CommandOperation, CommandOperationOptions, CollationOptions } from './command';
10
- import type { Server } from '../sdam/server';
11
- import type { Collection } from '../collection';
12
- import type { ObjectId, Document } from '../bson';
13
- import type { ClientSession } from '../sessions';
14
- import { MongoServerError, MongoInvalidArgumentError, MongoCompatibilityError } from '../error';
13
+ import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
14
+ import { Aspect, defineAspects, Hint } from './operation';
15
15
 
16
16
  /** @public */
17
17
  export interface UpdateOptions extends CommandOperationOptions {
@@ -1,10 +1,10 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import type { Callback } from '../utils';
1
+ import type { Admin } from '../admin';
3
2
  import type { Document } from '../bson';
3
+ import { MongoRuntimeError } from '../error';
4
4
  import type { Server } from '../sdam/server';
5
- import type { Admin } from '../admin';
6
5
  import type { ClientSession } from '../sessions';
7
- import { MongoRuntimeError } from '../error';
6
+ import type { Callback } from '../utils';
7
+ import { CommandOperation, CommandOperationOptions } from './command';
8
8
 
9
9
  /** @public */
10
10
  export interface ValidateCollectionOptions extends CommandOperationOptions {
@@ -1,7 +1,7 @@
1
- import type { TagSet } from './sdam/server_description';
2
1
  import type { Document } from './bson';
3
- import type { ClientSession } from './sessions';
4
2
  import { MongoInvalidArgumentError } from './error';
3
+ import type { TagSet } from './sdam/server_description';
4
+ import type { ClientSession } from './sessions';
5
5
 
6
6
  /** @public */
7
7
  export type ReadPreferenceLike = ReadPreference | ReadPreferenceMode;
@@ -156,7 +156,10 @@ export class ReadPreference {
156
156
  }
157
157
 
158
158
  if (typeof readPreference === 'string') {
159
- return new ReadPreference(readPreference as ReadPreferenceMode, readPreferenceTags);
159
+ return new ReadPreference(readPreference as ReadPreferenceMode, readPreferenceTags, {
160
+ maxStalenessSeconds: options.maxStalenessSeconds,
161
+ hedge: options.hedge
162
+ });
160
163
  } else if (!(readPreference instanceof ReadPreference) && typeof readPreference === 'object') {
161
164
  const mode = readPreference.mode || readPreference.preference;
162
165
  if (mode && typeof mode === 'string') {
@@ -229,19 +232,27 @@ export class ReadPreference {
229
232
  }
230
233
 
231
234
  /**
232
- * Indicates that this readPreference needs the "slaveOk" bit when sent over the wire
233
- *
235
+ * Indicates that this readPreference needs the "secondaryOk" bit when sent over the wire
236
+ * @deprecated Use secondaryOk instead
234
237
  * @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
235
238
  */
236
239
  slaveOk(): boolean {
237
- const NEEDS_SLAVEOK = new Set<string>([
240
+ return this.secondaryOk();
241
+ }
242
+
243
+ /**
244
+ * Indicates that this readPreference needs the "SecondaryOk" bit when sent over the wire
245
+ * @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
246
+ */
247
+ secondaryOk(): boolean {
248
+ const NEEDS_SECONDARYOK = new Set<string>([
238
249
  ReadPreference.PRIMARY_PREFERRED,
239
250
  ReadPreference.SECONDARY,
240
251
  ReadPreference.SECONDARY_PREFERRED,
241
252
  ReadPreference.NEAREST
242
253
  ]);
243
254
 
244
- return NEEDS_SLAVEOK.has(this.mode);
255
+ return NEEDS_SECONDARYOK.has(this.mode);
245
256
  }
246
257
 
247
258
  /**
@@ -1,6 +1,6 @@
1
- import type { Timestamp, Binary, Long } from '../bson';
2
- import type { Topology } from './topology';
1
+ import type { Binary, Long, Timestamp } from '../bson';
3
2
  import type { ClientSession } from '../sessions';
3
+ import type { Topology } from './topology';
4
4
 
5
5
  // shared state names
6
6
  export const STATE_CLOSING = 'closing';
@@ -1,6 +1,6 @@
1
+ import type { Document } from '../bson';
1
2
  import type { ServerDescription } from './server_description';
2
3
  import type { TopologyDescription } from './topology_description';
3
- import type { Document } from '../bson';
4
4
 
5
5
  /**
6
6
  * Emitted when server description changes, but does NOT include changes to the RTT.
@@ -123,8 +123,8 @@ export class TopologyClosedEvent {
123
123
  }
124
124
 
125
125
  /**
126
- * Emitted when the server monitor’s ismaster command is started - immediately before
127
- * the ismaster command is serialized into raw BSON and written to the socket.
126
+ * Emitted when the server monitor’s hello command is started - immediately before
127
+ * the hello command is serialized into raw BSON and written to the socket.
128
128
  *
129
129
  * @public
130
130
  * @category Event
@@ -140,7 +140,7 @@ export class ServerHeartbeatStartedEvent {
140
140
  }
141
141
 
142
142
  /**
143
- * Emitted when the server monitor’s ismaster succeeds.
143
+ * Emitted when the server monitor’s hello succeeds.
144
144
  * @public
145
145
  * @category Event
146
146
  */
@@ -161,7 +161,7 @@ export class ServerHeartbeatSucceededEvent {
161
161
  }
162
162
 
163
163
  /**
164
- * Emitted when the server monitor’s ismaster fails, either with an “ok: 0” or a socket exception.
164
+ * Emitted when the server monitor’s hello fails, either with an “ok: 0” or a socket exception.
165
165
  * @public
166
166
  * @category Event
167
167
  */