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
package/src/collection.ts CHANGED
@@ -1,101 +1,104 @@
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> {
@@ -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;
267
273
  insertOne(
268
- doc: OptionalId<TSchema>,
274
+ doc: OptionalUnlessRequiredId<TSchema>,
275
+ options: InsertOneOptions
276
+ ): Promise<InsertOneResult<TSchema>>;
277
+ insertOne(
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>>;
319
+ insertMany(
320
+ docs: OptionalUnlessRequiredId<TSchema>[],
321
+ callback: Callback<InsertManyResult<TSchema>>
322
+ ): void;
310
323
  insertMany(
311
- docs: OptionalId<TSchema>[],
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 {
@@ -676,12 +692,16 @@ export class Collection<TSchema extends Document = Document> {
676
692
  * @param options - Optional settings for the command
677
693
  * @param callback - An optional callback, a Promise will be returned if none is provided
678
694
  */
679
- findOne(): Promise<TSchema | null>;
680
- findOne(callback: Callback<TSchema | null>): void;
681
- findOne(filter: Filter<TSchema>): Promise<TSchema | null>;
682
- findOne(filter: Filter<TSchema>, callback: Callback<TSchema | null>): void;
683
- findOne(filter: Filter<TSchema>, options: FindOptions): Promise<TSchema | null>;
684
- findOne(filter: Filter<TSchema>, options: FindOptions, callback: Callback<TSchema | null>): void;
695
+ findOne(): Promise<WithId<TSchema> | null>;
696
+ findOne(callback: Callback<WithId<TSchema> | null>): void;
697
+ findOne(filter: Filter<TSchema>): Promise<WithId<TSchema> | null>;
698
+ findOne(filter: Filter<TSchema>, callback: Callback<WithId<TSchema> | null>): void;
699
+ findOne(filter: Filter<TSchema>, options: FindOptions): Promise<WithId<TSchema> | null>;
700
+ findOne(
701
+ filter: Filter<TSchema>,
702
+ options: FindOptions,
703
+ callback: Callback<WithId<TSchema> | null>
704
+ ): void;
685
705
 
686
706
  // allow an override of the schema.
687
707
  findOne<T = TSchema>(): Promise<T | null>;
@@ -695,10 +715,10 @@ export class Collection<TSchema extends Document = Document> {
695
715
  ): void;
696
716
 
697
717
  findOne(
698
- filter?: Filter<TSchema> | Callback<TSchema | null>,
699
- options?: FindOptions | Callback<TSchema | null>,
700
- callback?: Callback<TSchema | null>
701
- ): Promise<TSchema | null> | void {
718
+ filter?: Filter<TSchema> | Callback<WithId<TSchema> | null>,
719
+ options?: FindOptions | Callback<WithId<TSchema> | null>,
720
+ callback?: Callback<WithId<TSchema> | null>
721
+ ): Promise<WithId<TSchema> | null> | void {
702
722
  if (callback != null && typeof callback !== 'function') {
703
723
  throw new MongoInvalidArgumentError(
704
724
  'Third parameter to `findOne()` must be a callback or undefined'
@@ -706,7 +726,7 @@ export class Collection<TSchema extends Document = Document> {
706
726
  }
707
727
 
708
728
  if (typeof filter === 'function') {
709
- callback = filter as Callback<TSchema | null>;
729
+ callback = filter as Callback<WithId<TSchema> | null>;
710
730
  filter = {};
711
731
  options = {};
712
732
  }
@@ -725,10 +745,10 @@ export class Collection<TSchema extends Document = Document> {
725
745
  *
726
746
  * @param filter - The filter predicate. If unspecified, then all documents in the collection will match the predicate
727
747
  */
728
- find(): FindCursor<TSchema>;
729
- find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema>;
748
+ find(): FindCursor<WithId<TSchema>>;
749
+ find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<WithId<TSchema>>;
730
750
  find<T>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;
731
- find(filter?: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema> {
751
+ find(filter?: Filter<TSchema>, options?: FindOptions): FindCursor<WithId<TSchema>> {
732
752
  if (arguments.length > 2) {
733
753
  throw new MongoInvalidArgumentError(
734
754
  'Method "collection.find()" accepts at most two arguments'
@@ -738,7 +758,7 @@ export class Collection<TSchema extends Document = Document> {
738
758
  throw new MongoInvalidArgumentError('Argument "options" must not be function');
739
759
  }
740
760
 
741
- return new FindCursor<TSchema>(
761
+ return new FindCursor<WithId<TSchema>>(
742
762
  getTopology(this),
743
763
  this.s.namespace,
744
764
  filter,
@@ -1275,26 +1295,29 @@ export class Collection<TSchema extends Document = Document> {
1275
1295
  * @param options - Optional settings for the command
1276
1296
  * @param callback - An optional callback, a Promise will be returned if none is provided
1277
1297
  */
1278
- findOneAndReplace(filter: Filter<TSchema>, replacement: Document): Promise<ModifyResult<TSchema>>;
1279
1298
  findOneAndReplace(
1280
1299
  filter: Filter<TSchema>,
1281
- replacement: Document,
1300
+ replacement: WithoutId<TSchema>
1301
+ ): Promise<ModifyResult<TSchema>>;
1302
+ findOneAndReplace(
1303
+ filter: Filter<TSchema>,
1304
+ replacement: WithoutId<TSchema>,
1282
1305
  callback: Callback<ModifyResult<TSchema>>
1283
1306
  ): void;
1284
1307
  findOneAndReplace(
1285
1308
  filter: Filter<TSchema>,
1286
- replacement: Document,
1309
+ replacement: WithoutId<TSchema>,
1287
1310
  options: FindOneAndReplaceOptions
1288
1311
  ): Promise<ModifyResult<TSchema>>;
1289
1312
  findOneAndReplace(
1290
1313
  filter: Filter<TSchema>,
1291
- replacement: Document,
1314
+ replacement: WithoutId<TSchema>,
1292
1315
  options: FindOneAndReplaceOptions,
1293
1316
  callback: Callback<ModifyResult<TSchema>>
1294
1317
  ): void;
1295
1318
  findOneAndReplace(
1296
1319
  filter: Filter<TSchema>,
1297
- replacement: Document,
1320
+ replacement: WithoutId<TSchema>,
1298
1321
  options?: FindOneAndReplaceOptions | Callback<ModifyResult<TSchema>>,
1299
1322
  callback?: Callback<ModifyResult<TSchema>>
1300
1323
  ): Promise<ModifyResult<TSchema>> | void {
@@ -1415,6 +1438,7 @@ export class Collection<TSchema extends Document = Document> {
1415
1438
  /**
1416
1439
  * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
1417
1440
  *
1441
+ * @deprecated collection.mapReduce is deprecated. Use the aggregation pipeline instead. Visit https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline for more information on how to translate map-reduce operations to the aggregation pipeline.
1418
1442
  * @param map - The mapping function.
1419
1443
  * @param reduce - The reduce function.
1420
1444
  * @param options - Optional settings for the command
@@ -1446,6 +1470,9 @@ export class Collection<TSchema extends Document = Document> {
1446
1470
  options?: MapReduceOptions<TKey, TValue> | Callback<Document | Document[]>,
1447
1471
  callback?: Callback<Document | Document[]>
1448
1472
  ): Promise<Document | Document[]> | void {
1473
+ emitWarningOnce(
1474
+ 'collection.mapReduce is deprecated. Use the aggregation pipeline instead. Visit https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline for more information on how to translate map-reduce operations to the aggregation pipeline.'
1475
+ );
1449
1476
  if ('function' === typeof options) (callback = options), (options = {});
1450
1477
  // Out must always be defined (make sure we don't break weirdly on pre 1.8+ servers)
1451
1478
  // TODO NODE-3339: Figure out if this is still necessary given we no longer officially support pre-1.8
@@ -1509,7 +1536,7 @@ export class Collection<TSchema extends Document = Document> {
1509
1536
  * @param callback - An optional callback, a Promise will be returned if none is provided
1510
1537
  */
1511
1538
  insert(
1512
- docs: OptionalId<TSchema>[],
1539
+ docs: OptionalUnlessRequiredId<TSchema>[],
1513
1540
  options: BulkWriteOptions,
1514
1541
  callback: Callback<InsertManyResult<TSchema>>
1515
1542
  ): Promise<InsertManyResult<TSchema>> | void {