mongodb 4.1.4 → 4.3.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.
Files changed (267) hide show
  1. package/README.md +16 -15
  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 +3 -4
  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 +16 -18
  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 +1 -1
  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 +102 -15
  36. package/lib/cmap/connect.js.map +1 -1
  37. package/lib/cmap/connection.js +27 -26
  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.map +1 -1
  46. package/lib/cmap/wire_protocol/constants.js +4 -4
  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 +46 -47
  50. package/lib/collection.js.map +1 -1
  51. package/lib/connection_string.js +106 -49
  52. package/lib/connection_string.js.map +1 -1
  53. package/lib/constants.js +108 -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 +2 -2
  83. package/lib/operations/add_user.js.map +1 -1
  84. package/lib/operations/aggregate.js +2 -3
  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 +9 -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 +23 -7
  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 +11 -6
  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 +4 -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/monitor.js +4 -4
  152. package/lib/sdam/monitor.js.map +1 -1
  153. package/lib/sdam/server.js +31 -31
  154. package/lib/sdam/server.js.map +1 -1
  155. package/lib/sdam/server_description.js +1 -1
  156. package/lib/sdam/server_description.js.map +1 -1
  157. package/lib/sdam/server_selection.js +38 -3
  158. package/lib/sdam/server_selection.js.map +1 -1
  159. package/lib/sdam/srv_polling.js +11 -11
  160. package/lib/sdam/srv_polling.js.map +1 -1
  161. package/lib/sdam/topology.js +40 -62
  162. package/lib/sdam/topology.js.map +1 -1
  163. package/lib/sdam/topology_description.js +36 -14
  164. package/lib/sdam/topology_description.js.map +1 -1
  165. package/lib/sessions.js +13 -28
  166. package/lib/sessions.js.map +1 -1
  167. package/lib/transactions.js +1 -1
  168. package/lib/transactions.js.map +1 -1
  169. package/lib/utils.js +90 -23
  170. package/lib/utils.js.map +1 -1
  171. package/mongodb.d.ts +159 -65
  172. package/mongodb.ts34.d.ts +184 -65
  173. package/package.json +26 -24
  174. package/src/admin.ts +9 -9
  175. package/src/bson.ts +26 -17
  176. package/src/bulk/common.ts +26 -20
  177. package/src/bulk/ordered.ts +4 -4
  178. package/src/bulk/unordered.ts +5 -5
  179. package/src/change_stream.ts +35 -32
  180. package/src/cmap/auth/auth_provider.ts +3 -3
  181. package/src/cmap/auth/gssapi.ts +8 -8
  182. package/src/cmap/auth/mongo_credentials.ts +2 -6
  183. package/src/cmap/auth/mongocr.ts +3 -2
  184. package/src/cmap/auth/mongodb_aws.ts +10 -11
  185. package/src/cmap/auth/plain.ts +1 -1
  186. package/src/cmap/auth/providers.ts +21 -0
  187. package/src/cmap/auth/scram.ts +9 -9
  188. package/src/cmap/auth/x509.ts +3 -3
  189. package/src/cmap/command_monitoring_events.ts +2 -2
  190. package/src/cmap/commands.ts +30 -19
  191. package/src/cmap/connect.ts +142 -22
  192. package/src/cmap/connection.ts +73 -52
  193. package/src/cmap/connection_pool.ts +39 -39
  194. package/src/cmap/connection_pool_events.ts +1 -1
  195. package/src/cmap/message_stream.ts +9 -8
  196. package/src/cmap/stream_description.ts +5 -5
  197. package/src/cmap/wire_protocol/compression.ts +2 -2
  198. package/src/cmap/wire_protocol/constants.ts +4 -4
  199. package/src/cmap/wire_protocol/shared.ts +10 -9
  200. package/src/collection.ts +133 -106
  201. package/src/connection_string.ts +141 -60
  202. package/src/constants.ts +116 -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 +49 -39
  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 +58 -32
  216. package/src/mongo_types.ts +98 -20
  217. package/src/operations/add_user.ts +6 -5
  218. package/src/operations/aggregate.ts +6 -7
  219. package/src/operations/bulk_write.ts +5 -5
  220. package/src/operations/collections.ts +2 -2
  221. package/src/operations/command.ts +19 -8
  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 +8 -7
  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 +30 -11
  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 +18 -10
  240. package/src/operations/list_databases.ts +4 -4
  241. package/src/operations/map_reduce.ts +10 -9
  242. package/src/operations/operation.ts +8 -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 +1 -1
  255. package/src/sdam/monitor.ts +13 -14
  256. package/src/sdam/server.ts +71 -61
  257. package/src/sdam/server_description.ts +4 -4
  258. package/src/sdam/server_selection.ts +46 -3
  259. package/src/sdam/srv_polling.ts +15 -13
  260. package/src/sdam/topology.ts +89 -90
  261. package/src/sdam/topology_description.ts +39 -15
  262. package/src/sessions.ts +31 -48
  263. package/src/transactions.ts +6 -6
  264. package/src/utils.ts +123 -43
  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,22 +1,26 @@
1
- import { ReadPreference } from '../read_preference';
1
+ import type { Document } from '../bson';
2
2
  import {
3
- MongoError,
4
3
  isRetryableError,
4
+ MongoCompatibilityError,
5
5
  MONGODB_ERROR_CODES,
6
- MongoRuntimeError,
6
+ MongoError,
7
+ MongoExpiredSessionError,
7
8
  MongoNetworkError,
8
- MongoCompatibilityError,
9
+ MongoRuntimeError,
9
10
  MongoServerError,
10
- MongoExpiredSessionError,
11
11
  MongoTransactionError
12
12
  } from '../error';
13
- import { Aspect, AbstractOperation } from './operation';
14
- import { maxWireVersion, maybePromise, Callback } from '../utils';
13
+ import { ReadPreference } from '../read_preference';
15
14
  import type { Server } from '../sdam/server';
15
+ import {
16
+ sameServerSelector,
17
+ secondaryWritableServerSelector,
18
+ ServerSelector
19
+ } from '../sdam/server_selection';
16
20
  import type { Topology } from '../sdam/topology';
17
21
  import type { ClientSession } from '../sessions';
18
- import type { Document } from '../bson';
19
- import { supportsRetryableWrites } from '../utils';
22
+ import { Callback, maxWireVersion, maybePromise, supportsRetryableWrites } from '../utils';
23
+ import { AbstractOperation, Aspect } from './operation';
20
24
 
21
25
  const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
22
26
  const MMAPv1_RETRY_WRITES_ERROR_MESSAGE =
@@ -150,6 +154,21 @@ function executeWithServerSelection(
150
154
  session.unpin();
151
155
  }
152
156
 
157
+ let selector: ReadPreference | ServerSelector;
158
+
159
+ if (operation.hasAspect(Aspect.CURSOR_ITERATING)) {
160
+ // Get more operations must always select the same server, but run through
161
+ // server selection to potentially force monitor checks if the server is
162
+ // in an unknown state.
163
+ selector = sameServerSelector(operation.server?.description);
164
+ } else if (operation.trySecondaryWrite) {
165
+ // If operation should try to write to secondary use the custom server selector
166
+ // otherwise provide the read preference.
167
+ selector = secondaryWritableServerSelector(topology.commonWireVersion, readPreference);
168
+ } else {
169
+ selector = readPreference;
170
+ }
171
+
153
172
  const serverSelectionOptions = { session };
154
173
  function callbackWithRetry(err?: any, result?: any) {
155
174
  if (err == null) {
@@ -182,7 +201,7 @@ function executeWithServerSelection(
182
201
  }
183
202
 
184
203
  // select a new server, and attempt to retry the operation
185
- topology.selectServer(readPreference, serverSelectionOptions, (e?: any, server?: any) => {
204
+ topology.selectServer(selector, serverSelectionOptions, (e?: any, server?: any) => {
186
205
  if (
187
206
  e ||
188
207
  (operation.hasAspect(Aspect.READ_OPERATION) && !supportsRetryableReads(server)) ||
@@ -227,7 +246,7 @@ function executeWithServerSelection(
227
246
  }
228
247
 
229
248
  // select a server, and execute the operation against it
230
- topology.selectServer(readPreference, serverSelectionOptions, (err?: any, server?: any) => {
249
+ topology.selectServer(selector, serverSelectionOptions, (err?: any, server?: any) => {
231
250
  if (err) {
232
251
  callback(err);
233
252
  return;
@@ -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
 
@@ -15,6 +15,8 @@ const LIST_COLLECTIONS_WIRE_VERSION = 3;
15
15
  export interface ListCollectionsOptions extends CommandOperationOptions {
16
16
  /** Since 4.0: If true, will only return the collection name in the response, and will omit additional info */
17
17
  nameOnly?: boolean;
18
+ /** Since 4.0: If true and nameOnly is true, allows a user without the required privilege (i.e. listCollections action on the database) to run the command when access control is enforced. */
19
+ authorizedCollections?: boolean;
18
20
  /** The batchSize for the returned command cursor or if pre 2.8 the systems batch collection */
19
21
  batchSize?: number;
20
22
  }
@@ -25,6 +27,7 @@ export class ListCollectionsOperation extends CommandOperation<string[]> {
25
27
  db: Db;
26
28
  filter: Document;
27
29
  nameOnly: boolean;
30
+ authorizedCollections: boolean;
28
31
  batchSize?: number;
29
32
 
30
33
  constructor(db: Db, filter: Document, options?: ListCollectionsOptions) {
@@ -34,6 +37,7 @@ export class ListCollectionsOperation extends CommandOperation<string[]> {
34
37
  this.db = db;
35
38
  this.filter = filter;
36
39
  this.nameOnly = !!this.options.nameOnly;
40
+ this.authorizedCollections = !!this.options.authorizedCollections;
37
41
 
38
42
  if (typeof this.options.batchSize === 'number') {
39
43
  this.batchSize = this.options.batchSize;
@@ -90,14 +94,18 @@ export class ListCollectionsOperation extends CommandOperation<string[]> {
90
94
  return;
91
95
  }
92
96
 
93
- const command = {
97
+ return super.executeCommand(server, session, this.generateCommand(), callback);
98
+ }
99
+
100
+ /* This is here for the purpose of unit testing the final command that gets sent. */
101
+ generateCommand(): Document {
102
+ return {
94
103
  listCollections: 1,
95
104
  filter: this.filter,
96
105
  cursor: this.batchSize ? { batchSize: this.batchSize } : {},
97
- nameOnly: this.nameOnly
106
+ nameOnly: this.nameOnly,
107
+ authorizedCollections: this.authorizedCollections
98
108
  };
99
-
100
- return super.executeCommand(server, session, command, callback);
101
109
  }
102
110
  }
103
111
 
@@ -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 */
@@ -31,6 +32,7 @@ export interface OperationOptions extends BSONSerializeOptions {
31
32
 
32
33
  /** @internal Hints to `executeOperation` that this operation should not unpin on an ended transaction */
33
34
  bypassPinningCheck?: boolean;
35
+ omitReadPreference?: boolean;
34
36
  }
35
37
 
36
38
  /** @internal */
@@ -49,6 +51,7 @@ export abstract class AbstractOperation<TResult = any> {
49
51
  readPreference: ReadPreference;
50
52
  server!: Server;
51
53
  bypassPinningCheck: boolean;
54
+ trySecondaryWrite: boolean;
52
55
 
53
56
  // BSON serialization options
54
57
  bsonOptions?: BSONSerializeOptions;
@@ -72,6 +75,7 @@ export abstract class AbstractOperation<TResult = any> {
72
75
 
73
76
  this.options = options;
74
77
  this.bypassPinningCheck = !!options.bypassPinningCheck;
78
+ this.trySecondaryWrite = false;
75
79
  }
76
80
 
77
81
  abstract execute(server: Server, session: ClientSession, callback: Callback<TResult>): void;
@@ -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 {