mongodb 3.3.0-beta1 → 3.3.2

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 (66) hide show
  1. package/HISTORY.md +117 -0
  2. package/index.js +1 -0
  3. package/lib/admin.js +6 -6
  4. package/lib/aggregation_cursor.js +180 -226
  5. package/lib/change_stream.js +233 -121
  6. package/lib/collection.js +74 -39
  7. package/lib/command_cursor.js +87 -165
  8. package/lib/core/connection/connect.js +1 -1
  9. package/lib/core/connection/msg.js +2 -1
  10. package/lib/core/connection/pool.js +66 -41
  11. package/lib/core/cursor.js +605 -461
  12. package/lib/core/error.js +70 -1
  13. package/lib/core/index.js +1 -1
  14. package/lib/core/sdam/server.js +109 -10
  15. package/lib/core/sdam/server_description.js +14 -0
  16. package/lib/core/sdam/topology.js +34 -14
  17. package/lib/core/sdam/topology_description.js +6 -14
  18. package/lib/core/sessions.js +68 -12
  19. package/lib/core/topologies/mongos.js +10 -3
  20. package/lib/core/topologies/replset.js +49 -11
  21. package/lib/core/topologies/server.js +38 -3
  22. package/lib/core/topologies/shared.js +22 -0
  23. package/lib/core/transactions.js +1 -0
  24. package/lib/core/utils.js +45 -1
  25. package/lib/core/wireprotocol/command.js +2 -2
  26. package/lib/core/wireprotocol/get_more.js +4 -0
  27. package/lib/core/wireprotocol/query.js +8 -1
  28. package/lib/cursor.js +780 -840
  29. package/lib/db.js +31 -73
  30. package/lib/error.js +10 -8
  31. package/lib/gridfs-stream/download.js +12 -5
  32. package/lib/mongo_client.js +33 -21
  33. package/lib/operations/aggregate.js +77 -95
  34. package/lib/operations/close.js +46 -0
  35. package/lib/operations/collection_ops.js +7 -916
  36. package/lib/operations/command.js +2 -1
  37. package/lib/operations/command_v2.js +109 -0
  38. package/lib/operations/common_functions.js +48 -14
  39. package/lib/operations/connect.js +73 -9
  40. package/lib/operations/count.js +8 -8
  41. package/lib/operations/count_documents.js +24 -29
  42. package/lib/operations/create_collection.js +1 -0
  43. package/lib/operations/cursor_ops.js +22 -32
  44. package/lib/operations/db_ops.js +0 -178
  45. package/lib/operations/distinct.js +20 -21
  46. package/lib/operations/drop.js +1 -0
  47. package/lib/operations/estimated_document_count.js +43 -18
  48. package/lib/operations/execute_operation.js +115 -3
  49. package/lib/operations/explain.js +2 -6
  50. package/lib/operations/find.js +35 -0
  51. package/lib/operations/insert_one.js +1 -37
  52. package/lib/operations/list_collections.js +106 -0
  53. package/lib/operations/list_databases.js +38 -0
  54. package/lib/operations/list_indexes.js +28 -52
  55. package/lib/operations/operation.js +7 -1
  56. package/lib/operations/rename.js +1 -1
  57. package/lib/operations/to_array.js +3 -5
  58. package/lib/read_concern.js +7 -1
  59. package/lib/topologies/mongos.js +1 -1
  60. package/lib/topologies/replset.js +1 -1
  61. package/lib/topologies/server.js +2 -2
  62. package/lib/topologies/topology_base.js +4 -5
  63. package/lib/utils.js +4 -4
  64. package/package.json +1 -1
  65. package/lib/operations/aggregate_operation.js +0 -127
  66. package/lib/operations/mongo_client_ops.js +0 -731
package/HISTORY.md CHANGED
@@ -2,6 +2,123 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ <a name="3.3.2"></a>
6
+ ## [3.3.2](https://github.com/mongodb/node-mongodb-native/compare/v3.3.1...v3.3.2) (2019-08-28)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **change-stream:** default to server default batch size ([b3ae4c5](https://github.com/mongodb/node-mongodb-native/commit/b3ae4c5))
12
+ * **execute-operation:** return promise on session support check ([a976c14](https://github.com/mongodb/node-mongodb-native/commit/a976c14))
13
+ * **gridfs-stream:** ensure `close` is emitted after last chunk ([ae94cb9](https://github.com/mongodb/node-mongodb-native/commit/ae94cb9))
14
+
15
+
16
+
17
+ <a name="3.3.1"></a>
18
+ ## [3.3.1](https://github.com/mongodb/node-mongodb-native/compare/v3.3.0...v3.3.1) (2019-08-23)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * **find:** respect client-level provided read preference ([fec4f15](https://github.com/mongodb/node-mongodb-native/commit/fec4f15))
24
+ * correct inverted defaults for unified topology ([cf598e1](https://github.com/mongodb/node-mongodb-native/commit/cf598e1))
25
+
26
+
27
+
28
+ <a name="3.3.0"></a>
29
+ # [3.3.0](https://github.com/mongodb/node-mongodb-native/compare/v3.3.0-alpha1...v3.3.0) (2019-08-13)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * **aggregate-operation:** move type assertions to constructor ([25b27ff](https://github.com/mongodb/node-mongodb-native/commit/25b27ff))
35
+ * **autoEncryption:** tear down mongocryptd client when main client closes ([fe2f57e](https://github.com/mongodb/node-mongodb-native/commit/fe2f57e))
36
+ * **autoEncryption:** use new url parser for autoEncryption client ([d3670c2](https://github.com/mongodb/node-mongodb-native/commit/d3670c2))
37
+ * **Bulk:** change BulkWriteError message to first item from writeErrors ([#2013](https://github.com/mongodb/node-mongodb-native/issues/2013)) ([6bcf1e4](https://github.com/mongodb/node-mongodb-native/commit/6bcf1e4))
38
+ * **change_stream:** emit 'close' event if reconnecting failed ([41aba90](https://github.com/mongodb/node-mongodb-native/commit/41aba90))
39
+ * **change_stream:** emit close event after cursor is closed during error ([c2d80b2](https://github.com/mongodb/node-mongodb-native/commit/c2d80b2))
40
+ * **change-streams:** don't copy irrelevant resume options ([f190072](https://github.com/mongodb/node-mongodb-native/commit/f190072))
41
+ * **changestream:** removes all event listeners on close ([30eeeb5](https://github.com/mongodb/node-mongodb-native/commit/30eeeb5))
42
+ * **ChangeStream:** remove startAtOperationTime once we have resumeToken ([8d27e6e](https://github.com/mongodb/node-mongodb-native/commit/8d27e6e))
43
+ * **ClientSessions:** initialize clientOptions and cluster time ([b95d64e](https://github.com/mongodb/node-mongodb-native/commit/b95d64e))
44
+ * **connect:** don't treat 'connect' as an error event ([170a011](https://github.com/mongodb/node-mongodb-native/commit/170a011))
45
+ * **connect:** fixed syntax issue in connect error handler ([ff7166d](https://github.com/mongodb/node-mongodb-native/commit/ff7166d))
46
+ * **connections_stepdown_tests:** use correct version of mongo for tests ([ce2c9af](https://github.com/mongodb/node-mongodb-native/commit/ce2c9af))
47
+ * **createCollection:** Db.createCollection should pass readConcern to new collection ([#2026](https://github.com/mongodb/node-mongodb-native/issues/2026)) ([6145d4b](https://github.com/mongodb/node-mongodb-native/commit/6145d4b))
48
+ * **cursor:** do not truncate an existing Long ([317055b](https://github.com/mongodb/node-mongodb-native/commit/317055b)), closes [mongodb-js/mongodb-core#441](https://github.com/mongodb-js/mongodb-core/issues/441)
49
+ * **distinct:** return full response if `full` option was specified ([95a7d05](https://github.com/mongodb/node-mongodb-native/commit/95a7d05))
50
+ * **MongoClient:** allow Object.prototype items as db names ([dc6fc37](https://github.com/mongodb/node-mongodb-native/commit/dc6fc37))
51
+ * **MongoClient:** only check own properties for valid options ([c9dc717](https://github.com/mongodb/node-mongodb-native/commit/c9dc717))
52
+ * **OpMsg:** cap requestIds at 0x7fffffff ([c0e87d5](https://github.com/mongodb/node-mongodb-native/commit/c0e87d5))
53
+ * **read-operations:** send sessions on all read operations ([4d45c8a](https://github.com/mongodb/node-mongodb-native/commit/4d45c8a))
54
+ * **ReadPreference:** improve ReadPreference error message and remove irrelevant sharding test ([dd34ce4](https://github.com/mongodb/node-mongodb-native/commit/dd34ce4))
55
+ * **ReadPreference:** only allow valid ReadPreference modes ([06bbef2](https://github.com/mongodb/node-mongodb-native/commit/06bbef2))
56
+ * **replset:** correct legacy max staleness calculation ([2eab8aa](https://github.com/mongodb/node-mongodb-native/commit/2eab8aa))
57
+ * **replset:** introduce a fixed-time server selection loop ([cf53299](https://github.com/mongodb/node-mongodb-native/commit/cf53299))
58
+ * **server:** emit "first connect" error if initial connect fails due to ECONNREFUSED ([#2016](https://github.com/mongodb/node-mongodb-native/issues/2016)) ([5a7b15b](https://github.com/mongodb/node-mongodb-native/commit/5a7b15b))
59
+ * **serverSelection:** make sure to pass session to serverSelection ([eb5cc6b](https://github.com/mongodb/node-mongodb-native/commit/eb5cc6b))
60
+ * **sessions:** ensure an error is thrown when attempting sharded transactions ([3a1fdc1](https://github.com/mongodb/node-mongodb-native/commit/3a1fdc1))
61
+ * **topology:** add new error for retryWrites on MMAPv1 ([392f5a6](https://github.com/mongodb/node-mongodb-native/commit/392f5a6))
62
+ * don't check non-unified topologies for session support check ([2bccd3f](https://github.com/mongodb/node-mongodb-native/commit/2bccd3f))
63
+ * maintain internal database name on collection rename ([884d46f](https://github.com/mongodb/node-mongodb-native/commit/884d46f))
64
+ * only check for transaction state if session exists ([360975a](https://github.com/mongodb/node-mongodb-native/commit/360975a))
65
+ * preserve aggregate explain support for legacy servers ([032b204](https://github.com/mongodb/node-mongodb-native/commit/032b204))
66
+ * read concern only supported for `mapReduce` without inline ([51a36f3](https://github.com/mongodb/node-mongodb-native/commit/51a36f3))
67
+ * reintroduce support for 2.6 listIndexes ([c3bfc05](https://github.com/mongodb/node-mongodb-native/commit/c3bfc05))
68
+ * return `executeOperation` for explain, if promise is desired ([b4a7ad7](https://github.com/mongodb/node-mongodb-native/commit/b4a7ad7))
69
+ * validate atomic operations in all update methods ([88bb77e](https://github.com/mongodb/node-mongodb-native/commit/88bb77e))
70
+ * **transactions:** fix error message for attempting sharded ([eb5dfc9](https://github.com/mongodb/node-mongodb-native/commit/eb5dfc9))
71
+ * **transactions:** fix sharded transaction error logic ([083e18a](https://github.com/mongodb/node-mongodb-native/commit/083e18a))
72
+
73
+
74
+ ### Features
75
+
76
+ * **Aggregate:** support ReadConcern in aggregates with $out ([21cdcf0](https://github.com/mongodb/node-mongodb-native/commit/21cdcf0))
77
+ * **AutoEncryption:** improve error message for missing mongodb-client-encryption ([583f29f](https://github.com/mongodb/node-mongodb-native/commit/583f29f))
78
+ * **ChangeStream:** adds new resume functionality to ChangeStreams ([9ec9b8f](https://github.com/mongodb/node-mongodb-native/commit/9ec9b8f))
79
+ * **ChangeStreamCursor:** introduce new cursor type for change streams ([8813eb0](https://github.com/mongodb/node-mongodb-native/commit/8813eb0))
80
+ * **cryptdConnectionString:** makes mongocryptd uri configurable ([#2049](https://github.com/mongodb/node-mongodb-native/issues/2049)) ([a487be4](https://github.com/mongodb/node-mongodb-native/commit/a487be4))
81
+ * **eachAsync:** dedupe async iteration with a common helper ([c296f3a](https://github.com/mongodb/node-mongodb-native/commit/c296f3a))
82
+ * **execute-operation:** allow execution with server selection ([36bc1fd](https://github.com/mongodb/node-mongodb-native/commit/36bc1fd))
83
+ * **pool:** add support for resetting the connection pool ([2d1ff40](https://github.com/mongodb/node-mongodb-native/commit/2d1ff40))
84
+ * **sessions:** track dirty state of sessions, drop after use ([f61df16](https://github.com/mongodb/node-mongodb-native/commit/f61df16))
85
+ * add concept of `data-bearing` type to `ServerDescription` ([852e14f](https://github.com/mongodb/node-mongodb-native/commit/852e14f))
86
+ * **transaction:** allow applications to set maxTimeMS for commitTransaction ([b3948aa](https://github.com/mongodb/node-mongodb-native/commit/b3948aa))
87
+ * **Update:** add the ability to specify a pipeline to an update command ([#2017](https://github.com/mongodb/node-mongodb-native/issues/2017)) ([dc1387e](https://github.com/mongodb/node-mongodb-native/commit/dc1387e))
88
+ * add `known`, `data-bearing` filters to `TopologyDescription` ([d0ccb56](https://github.com/mongodb/node-mongodb-native/commit/d0ccb56))
89
+ * perform selection before cursor operation execution if needed ([808cf37](https://github.com/mongodb/node-mongodb-native/commit/808cf37))
90
+ * perform selection before operation execution if needed ([1a25876](https://github.com/mongodb/node-mongodb-native/commit/1a25876))
91
+ * support explain operations in `CommandOperationV2` ([86f5ba5](https://github.com/mongodb/node-mongodb-native/commit/86f5ba5))
92
+ * support operations passed to a `Cursor` or subclass ([b78bb89](https://github.com/mongodb/node-mongodb-native/commit/b78bb89))
93
+
94
+
95
+
96
+ <a name="3.2.7"></a>
97
+ ## [3.2.7](https://github.com/mongodb/node-mongodb-native/compare/v3.2.6...v3.2.7) (2019-06-04)
98
+
99
+
100
+ ### Bug Fixes
101
+
102
+ * **core:** updating core to version 3.2.7 ([2f91466](https://github.com/mongodb/node-mongodb-native/commit/2f91466))
103
+ * **findOneAndReplace:** throw error if atomic operators provided for findOneAndReplace ([6a860a3](https://github.com/mongodb/node-mongodb-native/commit/6a860a3))
104
+
105
+
106
+
107
+ <a name="3.2.6"></a>
108
+ ## [3.2.6](https://github.com/mongodb/node-mongodb-native/compare/v3.2.5...v3.2.6) (2019-05-24)
109
+
110
+
111
+
112
+ <a name="3.2.5"></a>
113
+ ## [3.2.5](https://github.com/mongodb/node-mongodb-native/compare/v3.2.4...v3.2.5) (2019-05-17)
114
+
115
+
116
+ ### Bug Fixes
117
+
118
+ * **core:** updating core to 3.2.5 ([a2766c1](https://github.com/mongodb/node-mongodb-native/commit/a2766c1))
119
+
120
+
121
+
5
122
  <a name="3.2.4"></a>
6
123
  ## [3.2.4](https://github.com/mongodb/node-mongodb-native/compare/v3.2.2...v3.2.4) (2019-05-08)
7
124
 
package/index.js CHANGED
@@ -10,6 +10,7 @@ const connect = require('./lib/mongo_client').connect;
10
10
  // Expose error class
11
11
  connect.MongoError = core.MongoError;
12
12
  connect.MongoNetworkError = core.MongoNetworkError;
13
+ connect.MongoTimeoutError = core.MongoTimeoutError;
13
14
 
14
15
  // Actual driver classes exported
15
16
  connect.Admin = require('./lib/admin');
package/lib/admin.js CHANGED
@@ -6,6 +6,7 @@ const AddUserOperation = require('./operations/add_user');
6
6
  const ExecuteDbAdminCommandOperation = require('./operations/execute_db_admin_command');
7
7
  const RemoveUserOperation = require('./operations/remove_user');
8
8
  const ValidateCollectionOperation = require('./operations/validate_collection');
9
+ const ListDatabasesOperation = require('./operations/list_databases');
9
10
 
10
11
  const executeOperation = require('./operations/execute_operation');
11
12
 
@@ -261,12 +262,11 @@ Admin.prototype.listDatabases = function(options, callback) {
261
262
  if (typeof options === 'function') (callback = options), (options = {});
262
263
  options = options || {};
263
264
 
264
- const cmd = { listDatabases: 1 };
265
- if (options.nameOnly) cmd.nameOnly = Number(cmd.nameOnly);
266
-
267
- const listDatabasesOperation = new ExecuteDbAdminCommandOperation(this.s.db, cmd, options);
268
-
269
- return executeOperation(this.s.db.s.topology, listDatabasesOperation, callback);
265
+ return executeOperation(
266
+ this.s.db.s.topology,
267
+ new ListDatabasesOperation(this.s.db, options),
268
+ callback
269
+ );
270
270
  };
271
271
 
272
272
  /**
@@ -1,12 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const inherits = require('util').inherits;
4
3
  const MongoError = require('./core').MongoError;
5
- const Readable = require('stream').Readable;
6
- const CoreCursor = require('./cursor');
4
+ const Cursor = require('./cursor');
5
+ const CursorState = require('./core/cursor').CursorState;
7
6
  const deprecate = require('util').deprecate;
8
- const SUPPORTS = require('./utils').SUPPORTS;
9
- const MongoDBNamespace = require('./utils').MongoDBNamespace;
10
7
 
11
8
  /**
12
9
  * @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
@@ -56,251 +53,211 @@ const MongoDBNamespace = require('./utils').MongoDBNamespace;
56
53
  * @fires AggregationCursor#readable
57
54
  * @return {AggregationCursor} an AggregationCursor instance.
58
55
  */
59
- var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptions) {
60
- CoreCursor.apply(this, Array.prototype.slice.call(arguments, 0));
61
- var state = AggregationCursor.INIT;
62
- var streamOptions = {};
63
-
64
- // MaxTimeMS
65
- var maxTimeMS = null;
66
-
67
- // Get the promiseLibrary
68
- var promiseLibrary = options.promiseLibrary || Promise;
69
-
70
- // Set up
71
- Readable.call(this, { objectMode: true });
72
-
73
- // Internal state
74
- this.s = {
75
- // MaxTimeMS
76
- maxTimeMS: maxTimeMS,
77
- // State
78
- state: state,
79
- // Stream options
80
- streamOptions: streamOptions,
81
- // BSON
82
- bson: bson,
83
- // Namespace
84
- // TODO: switch to raw namespace object later
85
- namespace: MongoDBNamespace.fromString(ns),
86
- // Command
87
- cmd: cmd,
88
- // Options
89
- options: options,
90
- // Topology
91
- topology: topology,
92
- // Topology Options
93
- topologyOptions: topologyOptions,
94
- // Promise library
95
- promiseLibrary: promiseLibrary,
96
- // Optional ClientSession
97
- session: options.session
98
- };
99
- };
56
+ class AggregationCursor extends Cursor {
57
+ constructor(topology, operation, options) {
58
+ super(topology, operation, options);
59
+ }
100
60
 
101
- /**
102
- * AggregationCursor stream data event, fired for each document in the cursor.
103
- *
104
- * @event AggregationCursor#data
105
- * @type {object}
106
- */
61
+ /**
62
+ * Set the batch size for the cursor.
63
+ * @method
64
+ * @param {number} value The batchSize for the cursor.
65
+ * @throws {MongoError}
66
+ * @return {AggregationCursor}
67
+ */
68
+ batchSize(value) {
69
+ if (this.s.state === CursorState.CLOSED || this.isDead()) {
70
+ throw MongoError.create({ message: 'Cursor is closed', driver: true });
71
+ }
72
+
73
+ if (typeof value !== 'number') {
74
+ throw MongoError.create({ message: 'batchSize requires an integer', driver: true });
75
+ }
76
+
77
+ this.operation.options.batchSize = value;
78
+ this.setCursorBatchSize(value);
79
+ return this;
80
+ }
107
81
 
108
- /**
109
- * AggregationCursor stream end event
110
- *
111
- * @event AggregationCursor#end
112
- * @type {null}
113
- */
82
+ /**
83
+ * Add a geoNear stage to the aggregation pipeline
84
+ * @method
85
+ * @param {object} document The geoNear stage document.
86
+ * @return {AggregationCursor}
87
+ */
88
+ geoNear(document) {
89
+ this.operation.addToPipeline({ $geoNear: document });
90
+ return this;
91
+ }
114
92
 
115
- /**
116
- * AggregationCursor stream close event
117
- *
118
- * @event AggregationCursor#close
119
- * @type {null}
120
- */
93
+ /**
94
+ * Add a group stage to the aggregation pipeline
95
+ * @method
96
+ * @param {object} document The group stage document.
97
+ * @return {AggregationCursor}
98
+ */
99
+ group(document) {
100
+ this.operation.addToPipeline({ $group: document });
101
+ return this;
102
+ }
121
103
 
122
- /**
123
- * AggregationCursor stream readable event
124
- *
125
- * @event AggregationCursor#readable
126
- * @type {null}
127
- */
104
+ /**
105
+ * Add a limit stage to the aggregation pipeline
106
+ * @method
107
+ * @param {number} value The state limit value.
108
+ * @return {AggregationCursor}
109
+ */
110
+ limit(value) {
111
+ this.operation.addToPipeline({ $limit: value });
112
+ return this;
113
+ }
128
114
 
129
- // Inherit from Readable
130
- inherits(AggregationCursor, Readable);
115
+ /**
116
+ * Add a match stage to the aggregation pipeline
117
+ * @method
118
+ * @param {object} document The match stage document.
119
+ * @return {AggregationCursor}
120
+ */
121
+ match(document) {
122
+ this.operation.addToPipeline({ $match: document });
123
+ return this;
124
+ }
131
125
 
132
- // Extend the Cursor
133
- for (var name in CoreCursor.prototype) {
134
- AggregationCursor.prototype[name] = CoreCursor.prototype[name];
135
- }
136
- if (SUPPORTS.ASYNC_ITERATOR) {
137
- AggregationCursor.prototype[
138
- Symbol.asyncIterator
139
- ] = require('./async/async_iterator').asyncIterator;
140
- }
126
+ /**
127
+ * Add a maxTimeMS stage to the aggregation pipeline
128
+ * @method
129
+ * @param {number} value The state maxTimeMS value.
130
+ * @return {AggregationCursor}
131
+ */
132
+ maxTimeMS(value) {
133
+ this.operation.options.maxTimeMS = value;
134
+ return this;
135
+ }
141
136
 
142
- /**
143
- * Set the batch size for the cursor.
144
- * @method
145
- * @param {number} value The batchSize for the cursor.
146
- * @throws {MongoError}
147
- * @return {AggregationCursor}
148
- */
149
- AggregationCursor.prototype.batchSize = function(value) {
150
- if (this.s.state === AggregationCursor.CLOSED || this.isDead())
151
- throw MongoError.create({ message: 'Cursor is closed', driver: true });
152
- if (typeof value !== 'number')
153
- throw MongoError.create({ message: 'batchSize requires an integer', driver: true });
154
- if (this.s.cmd.cursor) this.s.cmd.cursor.batchSize = value;
155
- this.setCursorBatchSize(value);
156
- return this;
157
- };
137
+ /**
138
+ * Add a out stage to the aggregation pipeline
139
+ * @method
140
+ * @param {number} destination The destination name.
141
+ * @return {AggregationCursor}
142
+ */
143
+ out(destination) {
144
+ this.operation.addToPipeline({ $out: destination });
145
+ return this;
146
+ }
158
147
 
159
- /**
160
- * Add a geoNear stage to the aggregation pipeline
161
- * @method
162
- * @param {object} document The geoNear stage document.
163
- * @return {AggregationCursor}
164
- */
165
- AggregationCursor.prototype.geoNear = deprecate(function(document) {
166
- this.s.cmd.pipeline.push({ $geoNear: document });
167
- return this;
168
- }, 'The `$geoNear` stage is deprecated in MongoDB 4.0, and removed in version 4.2.');
148
+ /**
149
+ * Add a project stage to the aggregation pipeline
150
+ * @method
151
+ * @param {object} document The project stage document.
152
+ * @return {AggregationCursor}
153
+ */
154
+ project(document) {
155
+ this.operation.addToPipeline({ $project: document });
156
+ return this;
157
+ }
169
158
 
170
- /**
171
- * Add a group stage to the aggregation pipeline
172
- * @method
173
- * @param {object} document The group stage document.
174
- * @return {AggregationCursor}
175
- */
176
- AggregationCursor.prototype.group = function(document) {
177
- this.s.cmd.pipeline.push({ $group: document });
178
- return this;
179
- };
159
+ /**
160
+ * Add a lookup stage to the aggregation pipeline
161
+ * @method
162
+ * @param {object} document The lookup stage document.
163
+ * @return {AggregationCursor}
164
+ */
165
+ lookup(document) {
166
+ this.operation.addToPipeline({ $lookup: document });
167
+ return this;
168
+ }
180
169
 
181
- /**
182
- * Add a limit stage to the aggregation pipeline
183
- * @method
184
- * @param {number} value The state limit value.
185
- * @return {AggregationCursor}
186
- */
187
- AggregationCursor.prototype.limit = function(value) {
188
- this.s.cmd.pipeline.push({ $limit: value });
189
- return this;
190
- };
170
+ /**
171
+ * Add a redact stage to the aggregation pipeline
172
+ * @method
173
+ * @param {object} document The redact stage document.
174
+ * @return {AggregationCursor}
175
+ */
176
+ redact(document) {
177
+ this.operation.addToPipeline({ $redact: document });
178
+ return this;
179
+ }
191
180
 
192
- /**
193
- * Add a match stage to the aggregation pipeline
194
- * @method
195
- * @param {object} document The match stage document.
196
- * @return {AggregationCursor}
197
- */
198
- AggregationCursor.prototype.match = function(document) {
199
- this.s.cmd.pipeline.push({ $match: document });
200
- return this;
201
- };
181
+ /**
182
+ * Add a skip stage to the aggregation pipeline
183
+ * @method
184
+ * @param {number} value The state skip value.
185
+ * @return {AggregationCursor}
186
+ */
187
+ skip(value) {
188
+ this.operation.addToPipeline({ $skip: value });
189
+ return this;
190
+ }
202
191
 
203
- /**
204
- * Add a maxTimeMS stage to the aggregation pipeline
205
- * @method
206
- * @param {number} value The state maxTimeMS value.
207
- * @return {AggregationCursor}
208
- */
209
- AggregationCursor.prototype.maxTimeMS = function(value) {
210
- if (this.s.topology.lastIsMaster().minWireVersion > 2) {
211
- this.s.cmd.maxTimeMS = value;
192
+ /**
193
+ * Add a sort stage to the aggregation pipeline
194
+ * @method
195
+ * @param {object} document The sort stage document.
196
+ * @return {AggregationCursor}
197
+ */
198
+ sort(document) {
199
+ this.operation.addToPipeline({ $sort: document });
200
+ return this;
212
201
  }
213
- return this;
214
- };
215
202
 
216
- /**
217
- * Add a out stage to the aggregation pipeline
218
- * @method
219
- * @param {number} destination The destination name.
220
- * @return {AggregationCursor}
221
- */
222
- AggregationCursor.prototype.out = function(destination) {
223
- this.s.cmd.pipeline.push({ $out: destination });
224
- return this;
225
- };
203
+ /**
204
+ * Add a unwind stage to the aggregation pipeline
205
+ * @method
206
+ * @param {number} field The unwind field name.
207
+ * @return {AggregationCursor}
208
+ */
209
+ unwind(field) {
210
+ this.operation.addToPipeline({ $unwind: field });
211
+ return this;
212
+ }
226
213
 
227
- /**
228
- * Add a project stage to the aggregation pipeline
229
- * @method
230
- * @param {object} document The project stage document.
231
- * @return {AggregationCursor}
232
- */
233
- AggregationCursor.prototype.project = function(document) {
234
- this.s.cmd.pipeline.push({ $project: document });
235
- return this;
236
- };
214
+ /**
215
+ * Return the cursor logger
216
+ * @method
217
+ * @return {Logger} return the cursor logger
218
+ * @ignore
219
+ */
220
+ getLogger() {
221
+ return this.logger;
222
+ }
223
+ }
237
224
 
238
- /**
239
- * Add a lookup stage to the aggregation pipeline
240
- * @method
241
- * @param {object} document The lookup stage document.
242
- * @return {AggregationCursor}
243
- */
244
- AggregationCursor.prototype.lookup = function(document) {
245
- this.s.cmd.pipeline.push({ $lookup: document });
246
- return this;
247
- };
225
+ // aliases
226
+ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
248
227
 
249
- /**
250
- * Add a redact stage to the aggregation pipeline
251
- * @method
252
- * @param {object} document The redact stage document.
253
- * @return {AggregationCursor}
254
- */
255
- AggregationCursor.prototype.redact = function(document) {
256
- this.s.cmd.pipeline.push({ $redact: document });
257
- return this;
258
- };
228
+ // deprecated methods
229
+ deprecate(
230
+ AggregationCursor.prototype.geoNear,
231
+ 'The `$geoNear` stage is deprecated in MongoDB 4.0, and removed in version 4.2.'
232
+ );
259
233
 
260
234
  /**
261
- * Add a skip stage to the aggregation pipeline
262
- * @method
263
- * @param {number} value The state skip value.
264
- * @return {AggregationCursor}
235
+ * AggregationCursor stream data event, fired for each document in the cursor.
236
+ *
237
+ * @event AggregationCursor#data
238
+ * @type {object}
265
239
  */
266
- AggregationCursor.prototype.skip = function(value) {
267
- this.s.cmd.pipeline.push({ $skip: value });
268
- return this;
269
- };
270
240
 
271
241
  /**
272
- * Add a sort stage to the aggregation pipeline
273
- * @method
274
- * @param {object} document The sort stage document.
275
- * @return {AggregationCursor}
242
+ * AggregationCursor stream end event
243
+ *
244
+ * @event AggregationCursor#end
245
+ * @type {null}
276
246
  */
277
- AggregationCursor.prototype.sort = function(document) {
278
- this.s.cmd.pipeline.push({ $sort: document });
279
- return this;
280
- };
281
247
 
282
248
  /**
283
- * Add a unwind stage to the aggregation pipeline
284
- * @method
285
- * @param {number} field The unwind field name.
286
- * @return {AggregationCursor}
249
+ * AggregationCursor stream close event
250
+ *
251
+ * @event AggregationCursor#close
252
+ * @type {null}
287
253
  */
288
- AggregationCursor.prototype.unwind = function(field) {
289
- this.s.cmd.pipeline.push({ $unwind: field });
290
- return this;
291
- };
292
254
 
293
255
  /**
294
- * Return the cursor logger
295
- * @method
296
- * @return {Logger} return the cursor logger
297
- * @ignore
256
+ * AggregationCursor stream readable event
257
+ *
258
+ * @event AggregationCursor#readable
259
+ * @type {null}
298
260
  */
299
- AggregationCursor.prototype.getLogger = function() {
300
- return this.logger;
301
- };
302
-
303
- AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
304
261
 
305
262
  /**
306
263
  * Get the next available document from the cursor, returns null if no more documents are available.
@@ -351,6 +308,7 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
351
308
  * at any given time if batch size is specified. Otherwise, the caller is responsible
352
309
  * for making sure that the entire result can fit the memory.
353
310
  * @method AggregationCursor.prototype.each
311
+ * @deprecated
354
312
  * @param {AggregationCursor~resultCallback} callback The result callback.
355
313
  * @throws {MongoError}
356
314
  * @return {null}
@@ -400,7 +358,7 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
400
358
  * @param {MongoError} error An error instance representing the error during the execution.
401
359
  */
402
360
 
403
- /*
361
+ /**
404
362
  * Iterates over all the documents for this cursor using the iterator, callback pattern.
405
363
  * @method AggregationCursor.prototype.forEach
406
364
  * @param {AggregationCursor~iteratorCallback} iterator The iteration callback.
@@ -409,8 +367,4 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
409
367
  * @return {null}
410
368
  */
411
369
 
412
- AggregationCursor.INIT = 0;
413
- AggregationCursor.OPEN = 1;
414
- AggregationCursor.CLOSED = 2;
415
-
416
370
  module.exports = AggregationCursor;