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
package/src/collection.ts CHANGED
@@ -1,105 +1,108 @@
1
- import { DEFAULT_PK_FACTORY, emitWarningOnce, resolveOptions } from './utils';
2
- import { ReadPreference, ReadPreferenceLike } from './read_preference';
3
- import {
4
- normalizeHintField,
5
- checkCollectionName,
6
- MongoDBNamespace,
7
- Callback,
8
- getTopology
9
- } from './utils';
10
- import { Document, BSONSerializeOptions, resolveBSONOptions } from './bson';
11
- import { MongoInvalidArgumentError } from './error';
12
- import { UnorderedBulkOperation } from './bulk/unordered';
1
+ import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
2
+ import type { AnyBulkWriteOperation, BulkWriteOptions, BulkWriteResult } from './bulk/common';
13
3
  import { OrderedBulkOperation } from './bulk/ordered';
4
+ import { UnorderedBulkOperation } from './bulk/unordered';
14
5
  import { ChangeStream, ChangeStreamOptions } from './change_stream';
15
- import { WriteConcern, WriteConcernOptions } from './write_concern';
16
- import { ReadConcern, ReadConcernLike } from './read_concern';
17
6
  import { AggregationCursor } from './cursor/aggregation_cursor';
7
+ import { FindCursor } from './cursor/find_cursor';
8
+ import type { Db } from './db';
9
+ import { MongoInvalidArgumentError } from './error';
10
+ import type { Logger, LoggerOptions } from './logger';
11
+ import type { PkFactory } from './mongo_client';
12
+ import type {
13
+ Filter,
14
+ Flatten,
15
+ OptionalUnlessRequiredId,
16
+ TODO_NODE_3286,
17
+ UpdateFilter,
18
+ WithId,
19
+ WithoutId
20
+ } from './mongo_types';
18
21
  import type { AggregateOptions } from './operations/aggregate';
19
22
  import { BulkWriteOperation } from './operations/bulk_write';
23
+ import type { IndexInformationOptions } from './operations/common_functions';
24
+ import type { CountOptions } from './operations/count';
20
25
  import { CountDocumentsOperation, CountDocumentsOptions } from './operations/count_documents';
21
26
  import {
22
- CreateIndexesOperation,
23
- CreateIndexOperation,
24
- DropIndexOperation,
25
- DropIndexesOperation,
26
- IndexesOperation,
27
- IndexExistsOperation,
28
- IndexInformationOperation,
29
- CreateIndexesOptions,
30
- DropIndexesOptions,
31
- ListIndexesOptions,
32
- IndexSpecification,
33
- IndexDescription,
34
- ListIndexesCursor
35
- } from './operations/indexes';
27
+ DeleteManyOperation,
28
+ DeleteOneOperation,
29
+ DeleteOptions,
30
+ DeleteResult
31
+ } from './operations/delete';
36
32
  import { DistinctOperation, DistinctOptions } from './operations/distinct';
37
33
  import { DropCollectionOperation, DropCollectionOptions } from './operations/drop';
38
34
  import {
39
35
  EstimatedDocumentCountOperation,
40
36
  EstimatedDocumentCountOptions
41
37
  } from './operations/estimated_document_count';
38
+ import { executeOperation } from './operations/execute_operation';
42
39
  import type { FindOptions } from './operations/find';
43
40
  import {
44
41
  FindOneAndDeleteOperation,
45
- FindOneAndReplaceOperation,
46
- FindOneAndUpdateOperation,
47
42
  FindOneAndDeleteOptions,
43
+ FindOneAndReplaceOperation,
48
44
  FindOneAndReplaceOptions,
45
+ FindOneAndUpdateOperation,
49
46
  FindOneAndUpdateOptions
50
47
  } from './operations/find_and_modify';
51
48
  import {
49
+ CreateIndexesOperation,
50
+ CreateIndexesOptions,
51
+ CreateIndexOperation,
52
+ DropIndexesOperation,
53
+ DropIndexesOptions,
54
+ DropIndexOperation,
55
+ IndexDescription,
56
+ IndexesOperation,
57
+ IndexExistsOperation,
58
+ IndexInformationOperation,
59
+ IndexSpecification,
60
+ ListIndexesCursor,
61
+ ListIndexesOptions
62
+ } from './operations/indexes';
63
+ import {
64
+ InsertManyOperation,
65
+ InsertManyResult,
52
66
  InsertOneOperation,
53
67
  InsertOneOptions,
54
- InsertOneResult,
55
- InsertManyOperation,
56
- InsertManyResult
68
+ InsertOneResult
57
69
  } from './operations/insert';
58
- import {
59
- UpdateOneOperation,
60
- UpdateManyOperation,
61
- UpdateOptions,
62
- UpdateResult,
63
- ReplaceOneOperation,
64
- ReplaceOptions
65
- } from './operations/update';
66
- import {
67
- DeleteOneOperation,
68
- DeleteManyOperation,
69
- DeleteOptions,
70
- DeleteResult
71
- } from './operations/delete';
72
70
  import { IsCappedOperation } from './operations/is_capped';
73
71
  import {
74
- MapReduceOperation,
75
72
  MapFunction,
76
- ReduceFunction,
77
- MapReduceOptions
73
+ MapReduceOperation,
74
+ MapReduceOptions,
75
+ ReduceFunction
78
76
  } from './operations/map_reduce';
77
+ import type { Hint, OperationOptions } from './operations/operation';
79
78
  import { OptionsOperation } from './operations/options_operation';
80
79
  import { RenameOperation, RenameOptions } from './operations/rename';
81
80
  import { CollStats, CollStatsOperation, CollStatsOptions } from './operations/stats';
82
- import { executeOperation } from './operations/execute_operation';
83
- import type { Db } from './db';
84
- import type { OperationOptions, Hint } from './operations/operation';
85
- import type { IndexInformationOptions } from './operations/common_functions';
86
- import type { BulkWriteResult, BulkWriteOptions, AnyBulkWriteOperation } from './bulk/common';
87
- import type { PkFactory } from './mongo_client';
88
- import type { Logger, LoggerOptions } from './logger';
89
- import { FindCursor } from './cursor/find_cursor';
90
- import type { CountOptions } from './operations/count';
91
- import type {
92
- Filter,
93
- TODO_NODE_3286,
94
- UpdateFilter,
95
- WithId,
96
- OptionalId,
97
- Flatten
98
- } from './mongo_types';
81
+ import {
82
+ ReplaceOneOperation,
83
+ ReplaceOptions,
84
+ UpdateManyOperation,
85
+ UpdateOneOperation,
86
+ UpdateOptions,
87
+ UpdateResult
88
+ } from './operations/update';
89
+ import { ReadConcern, ReadConcernLike } from './read_concern';
90
+ import { ReadPreference, ReadPreferenceLike } from './read_preference';
91
+ import {
92
+ Callback,
93
+ checkCollectionName,
94
+ DEFAULT_PK_FACTORY,
95
+ emitWarningOnce,
96
+ getTopology,
97
+ MongoDBNamespace,
98
+ normalizeHintField,
99
+ resolveOptions
100
+ } from './utils';
101
+ import { WriteConcern, WriteConcernOptions } from './write_concern';
99
102
 
100
103
  /** @public */
101
104
  export interface ModifyResult<TSchema = Document> {
102
- value: TSchema | null;
105
+ value: WithId<TSchema> | null;
103
106
  lastErrorObject?: Document;
104
107
  ok: 0 | 1;
105
108
  }
@@ -109,6 +112,9 @@ export interface CollectionOptions
109
112
  extends BSONSerializeOptions,
110
113
  WriteConcernOptions,
111
114
  LoggerOptions {
115
+ /**
116
+ * @deprecated Use readPreference instead
117
+ */
112
118
  slaveOk?: boolean;
113
119
  /** Specify a read concern for the collection. (only MongoDB 3.2 or higher supported) */
114
120
  readConcern?: ReadConcernLike;
@@ -124,7 +130,6 @@ export interface CollectionPrivate {
124
130
  namespace: MongoDBNamespace;
125
131
  readPreference?: ReadPreference;
126
132
  bsonOptions: BSONSerializeOptions;
127
- slaveOk?: boolean;
128
133
  collectionHint?: Hint;
129
134
  readConcern?: ReadConcern;
130
135
  writeConcern?: WriteConcern;
@@ -178,8 +183,7 @@ export class Collection<TSchema extends Document = Document> {
178
183
  readPreference: ReadPreference.fromOptions(options),
179
184
  bsonOptions: resolveBSONOptions(options, db),
180
185
  readConcern: ReadConcern.fromOptions(options),
181
- writeConcern: WriteConcern.fromOptions(options),
182
- slaveOk: options == null || options.slaveOk == null ? db.slaveOk : options.slaveOk
186
+ writeConcern: WriteConcern.fromOptions(options)
183
187
  };
184
188
  }
185
189
 
@@ -261,16 +265,22 @@ export class Collection<TSchema extends Document = Document> {
261
265
  * @param options - Optional settings for the command
262
266
  * @param callback - An optional callback, a Promise will be returned if none is provided
263
267
  */
264
- insertOne(doc: OptionalId<TSchema>): Promise<InsertOneResult<TSchema>>;
265
- insertOne(doc: OptionalId<TSchema>, callback: Callback<InsertOneResult<TSchema>>): void;
266
- insertOne(doc: OptionalId<TSchema>, options: InsertOneOptions): Promise<InsertOneResult<TSchema>>;
268
+ insertOne(doc: OptionalUnlessRequiredId<TSchema>): Promise<InsertOneResult<TSchema>>;
269
+ insertOne(
270
+ doc: OptionalUnlessRequiredId<TSchema>,
271
+ callback: Callback<InsertOneResult<TSchema>>
272
+ ): void;
273
+ insertOne(
274
+ doc: OptionalUnlessRequiredId<TSchema>,
275
+ options: InsertOneOptions
276
+ ): Promise<InsertOneResult<TSchema>>;
267
277
  insertOne(
268
- doc: OptionalId<TSchema>,
278
+ doc: OptionalUnlessRequiredId<TSchema>,
269
279
  options: InsertOneOptions,
270
280
  callback: Callback<InsertOneResult<TSchema>>
271
281
  ): void;
272
282
  insertOne(
273
- doc: OptionalId<TSchema>,
283
+ doc: OptionalUnlessRequiredId<TSchema>,
274
284
  options?: InsertOneOptions | Callback<InsertOneResult<TSchema>>,
275
285
  callback?: Callback<InsertOneResult<TSchema>>
276
286
  ): Promise<InsertOneResult<TSchema>> | void {
@@ -305,19 +315,22 @@ export class Collection<TSchema extends Document = Document> {
305
315
  * @param options - Optional settings for the command
306
316
  * @param callback - An optional callback, a Promise will be returned if none is provided
307
317
  */
308
- insertMany(docs: OptionalId<TSchema>[]): Promise<InsertManyResult<TSchema>>;
309
- insertMany(docs: OptionalId<TSchema>[], callback: Callback<InsertManyResult<TSchema>>): void;
318
+ insertMany(docs: OptionalUnlessRequiredId<TSchema>[]): Promise<InsertManyResult<TSchema>>;
310
319
  insertMany(
311
- docs: OptionalId<TSchema>[],
320
+ docs: OptionalUnlessRequiredId<TSchema>[],
321
+ callback: Callback<InsertManyResult<TSchema>>
322
+ ): void;
323
+ insertMany(
324
+ docs: OptionalUnlessRequiredId<TSchema>[],
312
325
  options: BulkWriteOptions
313
326
  ): Promise<InsertManyResult<TSchema>>;
314
327
  insertMany(
315
- docs: OptionalId<TSchema>[],
328
+ docs: OptionalUnlessRequiredId<TSchema>[],
316
329
  options: BulkWriteOptions,
317
330
  callback: Callback<InsertManyResult<TSchema>>
318
331
  ): void;
319
332
  insertMany(
320
- docs: OptionalId<TSchema>[],
333
+ docs: OptionalUnlessRequiredId<TSchema>[],
321
334
  options?: BulkWriteOptions | Callback<InsertManyResult<TSchema>>,
322
335
  callback?: Callback<InsertManyResult<TSchema>>
323
336
  ): Promise<InsertManyResult<TSchema>> | void {
@@ -459,26 +472,29 @@ export class Collection<TSchema extends Document = Document> {
459
472
  * @param options - Optional settings for the command
460
473
  * @param callback - An optional callback, a Promise will be returned if none is provided
461
474
  */
462
- replaceOne(filter: Filter<TSchema>, replacement: TSchema): Promise<UpdateResult | Document>;
463
475
  replaceOne(
464
476
  filter: Filter<TSchema>,
465
- replacement: TSchema,
477
+ replacement: WithoutId<TSchema>
478
+ ): Promise<UpdateResult | Document>;
479
+ replaceOne(
480
+ filter: Filter<TSchema>,
481
+ replacement: WithoutId<TSchema>,
466
482
  callback: Callback<UpdateResult | Document>
467
483
  ): void;
468
484
  replaceOne(
469
485
  filter: Filter<TSchema>,
470
- replacement: TSchema,
486
+ replacement: WithoutId<TSchema>,
471
487
  options: ReplaceOptions
472
488
  ): Promise<UpdateResult | Document>;
473
489
  replaceOne(
474
490
  filter: Filter<TSchema>,
475
- replacement: TSchema,
491
+ replacement: WithoutId<TSchema>,
476
492
  options: ReplaceOptions,
477
493
  callback: Callback<UpdateResult | Document>
478
494
  ): void;
479
495
  replaceOne(
480
496
  filter: Filter<TSchema>,
481
- replacement: TSchema,
497
+ replacement: WithoutId<TSchema>,
482
498
  options?: ReplaceOptions | Callback<UpdateResult | Document>,
483
499
  callback?: Callback<UpdateResult | Document>
484
500
  ): Promise<UpdateResult | Document> | void {
@@ -730,9 +746,9 @@ export class Collection<TSchema extends Document = Document> {
730
746
  * @param filter - The filter predicate. If unspecified, then all documents in the collection will match the predicate
731
747
  */
732
748
  find(): FindCursor<WithId<TSchema>>;
733
- find(filter: Filter<WithId<TSchema>>, options?: FindOptions): FindCursor<WithId<TSchema>>;
734
- find<T>(filter: Filter<WithId<TSchema>>, options?: FindOptions): FindCursor<T>;
735
- find(filter?: Filter<WithId<TSchema>>, options?: FindOptions): FindCursor<WithId<TSchema>> {
749
+ find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<WithId<TSchema>>;
750
+ find<T>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;
751
+ find(filter?: Filter<TSchema>, options?: FindOptions): FindCursor<WithId<TSchema>> {
736
752
  if (arguments.length > 2) {
737
753
  throw new MongoInvalidArgumentError(
738
754
  'Method "collection.find()" accepts at most two arguments'
@@ -1279,26 +1295,29 @@ export class Collection<TSchema extends Document = Document> {
1279
1295
  * @param options - Optional settings for the command
1280
1296
  * @param callback - An optional callback, a Promise will be returned if none is provided
1281
1297
  */
1282
- findOneAndReplace(filter: Filter<TSchema>, replacement: Document): Promise<ModifyResult<TSchema>>;
1283
1298
  findOneAndReplace(
1284
1299
  filter: Filter<TSchema>,
1285
- replacement: Document,
1300
+ replacement: WithoutId<TSchema>
1301
+ ): Promise<ModifyResult<TSchema>>;
1302
+ findOneAndReplace(
1303
+ filter: Filter<TSchema>,
1304
+ replacement: WithoutId<TSchema>,
1286
1305
  callback: Callback<ModifyResult<TSchema>>
1287
1306
  ): void;
1288
1307
  findOneAndReplace(
1289
1308
  filter: Filter<TSchema>,
1290
- replacement: Document,
1309
+ replacement: WithoutId<TSchema>,
1291
1310
  options: FindOneAndReplaceOptions
1292
1311
  ): Promise<ModifyResult<TSchema>>;
1293
1312
  findOneAndReplace(
1294
1313
  filter: Filter<TSchema>,
1295
- replacement: Document,
1314
+ replacement: WithoutId<TSchema>,
1296
1315
  options: FindOneAndReplaceOptions,
1297
1316
  callback: Callback<ModifyResult<TSchema>>
1298
1317
  ): void;
1299
1318
  findOneAndReplace(
1300
1319
  filter: Filter<TSchema>,
1301
- replacement: Document,
1320
+ replacement: WithoutId<TSchema>,
1302
1321
  options?: FindOneAndReplaceOptions | Callback<ModifyResult<TSchema>>,
1303
1322
  callback?: Callback<ModifyResult<TSchema>>
1304
1323
  ): Promise<ModifyResult<TSchema>> | void {
@@ -1517,7 +1536,7 @@ export class Collection<TSchema extends Document = Document> {
1517
1536
  * @param callback - An optional callback, a Promise will be returned if none is provided
1518
1537
  */
1519
1538
  insert(
1520
- docs: OptionalId<TSchema>[],
1539
+ docs: OptionalUnlessRequiredId<TSchema>[],
1521
1540
  options: BulkWriteOptions,
1522
1541
  callback: Callback<InsertManyResult<TSchema>>
1523
1542
  ): Promise<InsertManyResult<TSchema>> | void {
@@ -2,22 +2,14 @@ import * as dns from 'dns';
2
2
  import * as fs from 'fs';
3
3
  import ConnectionString from 'mongodb-connection-string-url';
4
4
  import { URLSearchParams } from 'url';
5
- import { AuthMechanism } from './cmap/auth/defaultAuthProviders';
6
- import { ReadPreference, ReadPreferenceMode } from './read_preference';
7
- import { ReadConcern, ReadConcernLevel } from './read_concern';
8
- import { W, WriteConcern } from './write_concern';
9
- import { MongoAPIError, MongoInvalidArgumentError, MongoParseError } from './error';
10
- import {
11
- AnyOptions,
12
- Callback,
13
- DEFAULT_PK_FACTORY,
14
- isRecord,
15
- makeClientMetadata,
16
- setDifference,
17
- HostAddress,
18
- emitWarning
19
- } from './utils';
5
+
20
6
  import type { Document } from './bson';
7
+ import { MongoCredentials } from './cmap/auth/mongo_credentials';
8
+ import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './cmap/auth/providers';
9
+ import { Compressor, CompressorName } from './cmap/wire_protocol/compression';
10
+ import { Encrypter } from './encrypter';
11
+ import { MongoAPIError, MongoInvalidArgumentError, MongoParseError } from './error';
12
+ import { Logger, LoggerLevel } from './logger';
21
13
  import {
22
14
  DriverInfo,
23
15
  MongoClient,
@@ -27,12 +19,21 @@ import {
27
19
  ServerApi,
28
20
  ServerApiVersion
29
21
  } from './mongo_client';
30
- import { MongoCredentials } from './cmap/auth/mongo_credentials';
31
- import type { TagSet } from './sdam/server_description';
32
- import { Logger, LoggerLevel } from './logger';
33
22
  import { PromiseProvider } from './promise_provider';
34
- import { Encrypter } from './encrypter';
35
- import { Compressor, CompressorName } from './cmap/wire_protocol/compression';
23
+ import { ReadConcern, ReadConcernLevel } from './read_concern';
24
+ import { ReadPreference, ReadPreferenceMode } from './read_preference';
25
+ import type { TagSet } from './sdam/server_description';
26
+ import {
27
+ AnyOptions,
28
+ Callback,
29
+ DEFAULT_PK_FACTORY,
30
+ emitWarning,
31
+ HostAddress,
32
+ isRecord,
33
+ makeClientMetadata,
34
+ setDifference
35
+ } from './utils';
36
+ import { W, WriteConcern } from './write_concern';
36
37
 
37
38
  const VALID_TXT_RECORDS = ['authSource', 'replicaSet', 'loadBalanced'];
38
39
 
@@ -124,7 +125,12 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
124
125
  const replicaSet = txtRecordOptions.get('replicaSet') ?? undefined;
125
126
  const loadBalanced = txtRecordOptions.get('loadBalanced') ?? undefined;
126
127
 
127
- if (!options.userSpecifiedAuthSource && source) {
128
+ if (
129
+ !options.userSpecifiedAuthSource &&
130
+ source &&
131
+ options.credentials &&
132
+ !AUTH_MECHS_AUTH_SRC_EXTERNAL.has(options.credentials.mechanism)
133
+ ) {
128
134
  options.credentials = MongoCredentials.merge(options.credentials, { source });
129
135
  }
130
136
 
@@ -291,11 +297,6 @@ export function parseOptions(
291
297
  }
292
298
  }
293
299
 
294
- if (urlOptions.has('authSource')) {
295
- // If authSource is an explicit key in the urlOptions we need to remove the dbName
296
- urlOptions.delete('dbName');
297
- }
298
-
299
300
  const objectOptions = new CaseInsensitiveMap(
300
301
  Object.entries(options).filter(([, v]) => v != null)
301
302
  );
@@ -453,6 +454,31 @@ export function parseOptions(
453
454
  }
454
455
  }
455
456
 
457
+ if (
458
+ !mongoOptions.proxyHost &&
459
+ (mongoOptions.proxyPort || mongoOptions.proxyUsername || mongoOptions.proxyPassword)
460
+ ) {
461
+ throw new MongoParseError('Must specify proxyHost if other proxy options are passed');
462
+ }
463
+
464
+ if (
465
+ (mongoOptions.proxyUsername && !mongoOptions.proxyPassword) ||
466
+ (!mongoOptions.proxyUsername && mongoOptions.proxyPassword)
467
+ ) {
468
+ throw new MongoParseError('Can only specify both of proxy username/password or neither');
469
+ }
470
+
471
+ if (
472
+ urlOptions.get('proxyHost')?.length > 1 ||
473
+ urlOptions.get('proxyPort')?.length > 1 ||
474
+ urlOptions.get('proxyUsername')?.length > 1 ||
475
+ urlOptions.get('proxyPassword')?.length > 1
476
+ ) {
477
+ throw new MongoParseError(
478
+ 'Proxy options cannot be specified multiple times in the connection string'
479
+ );
480
+ }
481
+
456
482
  return mongoOptions;
457
483
  }
458
484
 
@@ -574,9 +600,7 @@ export const OPTIONS = {
574
600
  let source = options.credentials?.source;
575
601
  if (
576
602
  mechanism === AuthMechanism.MONGODB_PLAIN ||
577
- mechanism === AuthMechanism.MONGODB_GSSAPI ||
578
- mechanism === AuthMechanism.MONGODB_AWS ||
579
- mechanism === AuthMechanism.MONGODB_X509
603
+ AUTH_MECHS_AUTH_SRC_EXTERNAL.has(mechanism)
580
604
  ) {
581
605
  // some mechanisms have '$external' as the Auth Source
582
606
  source = '$external';
@@ -693,6 +717,7 @@ export const OPTIONS = {
693
717
  });
694
718
  }
695
719
  },
720
+ enableUtf8Validation: { type: 'boolean', default: true },
696
721
  family: {
697
722
  transform({ name, values: [value] }): 4 | 6 {
698
723
  const transformValue = getInt(name, value);
@@ -860,6 +885,18 @@ export const OPTIONS = {
860
885
  promoteValues: {
861
886
  type: 'boolean'
862
887
  },
888
+ proxyHost: {
889
+ type: 'string'
890
+ },
891
+ proxyPassword: {
892
+ type: 'string'
893
+ },
894
+ proxyPort: {
895
+ type: 'uint'
896
+ },
897
+ proxyUsername: {
898
+ type: 'string'
899
+ },
863
900
  raw: {
864
901
  default: false,
865
902
  type: 'boolean'
package/src/constants.ts CHANGED
@@ -4,3 +4,125 @@ export const SYSTEM_PROFILE_COLLECTION = 'system.profile';
4
4
  export const SYSTEM_USER_COLLECTION = 'system.users';
5
5
  export const SYSTEM_COMMAND_COLLECTION = '$cmd';
6
6
  export const SYSTEM_JS_COLLECTION = 'system.js';
7
+
8
+ // events
9
+ export const ERROR = 'error' as const;
10
+ export const TIMEOUT = 'timeout' as const;
11
+ export const CLOSE = 'close' as const;
12
+ export const OPEN = 'open' as const;
13
+ export const CONNECT = 'connect' as const;
14
+ export const CLOSED = 'closed' as const;
15
+ export const ENDED = 'ended' as const;
16
+ export const MESSAGE = 'message' as const;
17
+ export const PINNED = 'pinned' as const;
18
+ export const UNPINNED = 'unpinned' as const;
19
+ export const DESCRIPTION_RECEIVED = 'descriptionReceived';
20
+ export const SERVER_OPENING = 'serverOpening' as const;
21
+ export const SERVER_CLOSED = 'serverClosed' as const;
22
+ export const SERVER_DESCRIPTION_CHANGED = 'serverDescriptionChanged' as const;
23
+ export const TOPOLOGY_OPENING = 'topologyOpening' as const;
24
+ export const TOPOLOGY_CLOSED = 'topologyClosed' as const;
25
+ export const TOPOLOGY_DESCRIPTION_CHANGED = 'topologyDescriptionChanged' as const;
26
+ export const CONNECTION_POOL_CREATED = 'connectionPoolCreated' as const;
27
+ export const CONNECTION_POOL_CLOSED = 'connectionPoolClosed' as const;
28
+ export const CONNECTION_POOL_CLEARED = 'connectionPoolCleared' as const;
29
+ export const CONNECTION_CREATED = 'connectionCreated' as const;
30
+ export const CONNECTION_READY = 'connectionReady' as const;
31
+ export const CONNECTION_CLOSED = 'connectionClosed' as const;
32
+ export const CONNECTION_CHECK_OUT_STARTED = 'connectionCheckOutStarted' as const;
33
+ export const CONNECTION_CHECK_OUT_FAILED = 'connectionCheckOutFailed' as const;
34
+ export const CONNECTION_CHECKED_OUT = 'connectionCheckedOut' as const;
35
+ export const CONNECTION_CHECKED_IN = 'connectionCheckedIn' as const;
36
+ export const CLUSTER_TIME_RECEIVED = 'clusterTimeReceived' as const;
37
+ export const COMMAND_STARTED = 'commandStarted' as const;
38
+ export const COMMAND_SUCCEEDED = 'commandSucceeded' as const;
39
+ export const COMMAND_FAILED = 'commandFailed' as const;
40
+ export const SERVER_HEARTBEAT_STARTED = 'serverHeartbeatStarted' as const;
41
+ export const SERVER_HEARTBEAT_SUCCEEDED = 'serverHeartbeatSucceeded' as const;
42
+ export const SERVER_HEARTBEAT_FAILED = 'serverHeartbeatFailed' as const;
43
+
44
+ /** @public */
45
+ export const HEARTBEAT_EVENTS = Object.freeze([
46
+ SERVER_HEARTBEAT_STARTED,
47
+ SERVER_HEARTBEAT_SUCCEEDED,
48
+ SERVER_HEARTBEAT_FAILED
49
+ ] as const);
50
+
51
+ /** @public */
52
+ export const CMAP_EVENTS = Object.freeze([
53
+ CONNECTION_POOL_CREATED,
54
+ CONNECTION_POOL_CLOSED,
55
+ CONNECTION_CREATED,
56
+ CONNECTION_READY,
57
+ CONNECTION_CLOSED,
58
+ CONNECTION_CHECK_OUT_STARTED,
59
+ CONNECTION_CHECK_OUT_FAILED,
60
+ CONNECTION_CHECKED_OUT,
61
+ CONNECTION_CHECKED_IN,
62
+ CONNECTION_POOL_CLEARED
63
+ ] as const);
64
+
65
+ /** @public */
66
+ export const TOPOLOGY_EVENTS = Object.freeze([
67
+ SERVER_OPENING,
68
+ SERVER_CLOSED,
69
+ SERVER_DESCRIPTION_CHANGED,
70
+ TOPOLOGY_OPENING,
71
+ TOPOLOGY_CLOSED,
72
+ TOPOLOGY_DESCRIPTION_CHANGED,
73
+ ERROR,
74
+ TIMEOUT,
75
+ CLOSE
76
+ ] as const);
77
+
78
+ /** @public */
79
+ export const APM_EVENTS = Object.freeze([
80
+ COMMAND_STARTED,
81
+ COMMAND_SUCCEEDED,
82
+ COMMAND_FAILED
83
+ ] as const);
84
+
85
+ /**
86
+ * All events that we relay to the `Topology`
87
+ * @internal
88
+ */
89
+ export const SERVER_RELAY_EVENTS = Object.freeze([
90
+ SERVER_HEARTBEAT_STARTED,
91
+ SERVER_HEARTBEAT_SUCCEEDED,
92
+ SERVER_HEARTBEAT_FAILED,
93
+ COMMAND_STARTED,
94
+ COMMAND_SUCCEEDED,
95
+ COMMAND_FAILED,
96
+ ...CMAP_EVENTS
97
+ ] as const);
98
+
99
+ /**
100
+ * All events we listen to from `Server` instances, but do not forward to the client
101
+ * @internal
102
+ */
103
+ export const LOCAL_SERVER_EVENTS = Object.freeze([
104
+ CONNECT,
105
+ DESCRIPTION_RECEIVED,
106
+ CLOSED,
107
+ ENDED
108
+ ] as const);
109
+
110
+ /** @public */
111
+ export const MONGO_CLIENT_EVENTS = Object.freeze([
112
+ ...CMAP_EVENTS,
113
+ ...APM_EVENTS,
114
+ ...TOPOLOGY_EVENTS,
115
+ ...HEARTBEAT_EVENTS
116
+ ] as const);
117
+
118
+ /**
119
+ * @internal
120
+ * The legacy hello command that was deprecated in MongoDB 5.0.
121
+ */
122
+ export const LEGACY_HELLO_COMMAND = 'ismaster';
123
+
124
+ /**
125
+ * @internal
126
+ * The legacy hello command that was deprecated in MongoDB 5.0.
127
+ */
128
+ export const LEGACY_HELLO_COMMAND_CAMEL_CASE = 'isMaster';
@@ -1,22 +1,24 @@
1
- import { Callback, maybePromise, MongoDBNamespace, ns } from '../utils';
2
- import { Long, Document, BSONSerializeOptions, pluckBSONSerializeOptions } from '../bson';
3
- import { ClientSession, maybeClearPinnedConnection } from '../sessions';
1
+ import { Readable, Transform } from 'stream';
2
+
3
+ import { BSONSerializeOptions, Document, Long, pluckBSONSerializeOptions } from '../bson';
4
4
  import {
5
5
  AnyError,
6
- MongoRuntimeError,
7
- MongoNetworkError,
8
- MongoInvalidArgumentError,
9
6
  MongoCursorExhaustedError,
10
- MongoTailableCursorError,
11
- MongoCursorInUseError
7
+ MongoCursorInUseError,
8
+ MongoInvalidArgumentError,
9
+ MongoNetworkError,
10
+ MongoRuntimeError,
11
+ MongoTailableCursorError
12
12
  } from '../error';
13
+ import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
14
+ import { executeOperation, ExecutionResult } from '../operations/execute_operation';
15
+ import { GetMoreOperation } from '../operations/get_more';
16
+ import { ReadConcern, ReadConcernLike } from '../read_concern';
13
17
  import { ReadPreference, ReadPreferenceLike } from '../read_preference';
14
18
  import type { Server } from '../sdam/server';
15
19
  import type { Topology } from '../sdam/topology';
16
- import { Readable, Transform } from 'stream';
17
- import type { ExecutionResult } from '../operations/execute_operation';
18
- import { ReadConcern, ReadConcernLike } from '../read_concern';
19
- import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
20
+ import { ClientSession, maybeClearPinnedConnection } from '../sessions';
21
+ import { Callback, maybePromise, MongoDBNamespace, ns } from '../utils';
20
22
 
21
23
  /** @internal */
22
24
  const kId = Symbol('id');
@@ -610,16 +612,13 @@ export abstract class AbstractCursor<
610
612
  return;
611
613
  }
612
614
 
613
- server.getMore(
614
- cursorNs,
615
- cursorId,
616
- {
617
- ...this[kOptions],
618
- session: this[kSession],
619
- batchSize
620
- },
621
- callback
622
- );
615
+ const getMoreOperation = new GetMoreOperation(cursorNs, cursorId, server, {
616
+ ...this[kOptions],
617
+ session: this[kSession],
618
+ batchSize
619
+ });
620
+
621
+ executeOperation(this.topology, getMoreOperation, callback);
623
622
  }
624
623
  }
625
624