mongodb 3.3.0-beta2 → 3.3.3
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.
- package/HISTORY.md +155 -0
- package/index.js +1 -0
- package/lib/admin.js +6 -6
- package/lib/aggregation_cursor.js +180 -228
- package/lib/bulk/common.js +150 -73
- package/lib/bulk/ordered.js +1 -1
- package/lib/bulk/unordered.js +1 -0
- package/lib/change_stream.js +66 -66
- package/lib/collection.js +131 -44
- package/lib/command_cursor.js +87 -167
- package/lib/core/connection/connection.js +7 -3
- package/lib/core/connection/msg.js +5 -3
- package/lib/core/connection/pool.js +114 -143
- package/lib/core/cursor.js +569 -435
- package/lib/core/error.js +63 -12
- package/lib/core/index.js +1 -1
- package/lib/core/sdam/monitoring.js +8 -1
- package/lib/core/sdam/server.js +58 -14
- package/lib/core/sdam/topology.js +66 -31
- package/lib/core/sdam/topology_description.js +1 -1
- package/lib/core/sessions.js +68 -12
- package/lib/core/topologies/mongos.js +81 -26
- package/lib/core/topologies/replset.js +56 -10
- package/lib/core/topologies/replset_state.js +5 -5
- package/lib/core/topologies/server.js +7 -2
- package/lib/core/topologies/shared.js +23 -0
- package/lib/core/transactions.js +1 -0
- package/lib/core/uri_parser.js +8 -2
- package/lib/core/utils.js +13 -1
- package/lib/core/wireprotocol/get_more.js +4 -0
- package/lib/core/wireprotocol/query.js +8 -1
- package/lib/cursor.js +782 -844
- package/lib/db.js +27 -75
- package/lib/gridfs-stream/download.js +12 -5
- package/lib/gridfs-stream/index.js +1 -1
- package/lib/mongo_client.js +27 -11
- package/lib/operations/aggregate.js +75 -101
- package/lib/operations/close.js +12 -13
- package/lib/operations/collection_ops.js +3 -916
- package/lib/operations/command_v2.js +70 -4
- package/lib/operations/common_functions.js +48 -14
- package/lib/operations/connect.js +29 -36
- package/lib/operations/count.js +8 -8
- package/lib/operations/count_documents.js +24 -29
- package/lib/operations/cursor_ops.js +22 -32
- package/lib/operations/db_ops.js +0 -178
- package/lib/operations/estimated_document_count.js +43 -18
- package/lib/operations/execute_operation.js +51 -18
- package/lib/operations/explain.js +2 -2
- package/lib/operations/find.js +35 -0
- package/lib/operations/insert_one.js +1 -37
- package/lib/operations/list_collections.js +106 -0
- package/lib/operations/list_databases.js +38 -0
- package/lib/operations/list_indexes.js +28 -52
- package/lib/operations/operation.js +4 -0
- package/lib/operations/rename.js +1 -1
- package/lib/operations/replace_one.js +1 -1
- package/lib/operations/to_array.js +3 -5
- package/lib/read_concern.js +7 -1
- package/lib/topologies/mongos.js +1 -1
- package/lib/topologies/replset.js +1 -1
- package/lib/topologies/server.js +2 -2
- package/lib/topologies/topology_base.js +4 -5
- package/lib/utils.js +4 -4
- package/package.json +9 -5
- package/lib/operations/aggregate_operation.js +0 -127
|
@@ -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
|
|
6
|
-
const
|
|
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,253 +53,211 @@ const MongoDBNamespace = require('./utils').MongoDBNamespace;
|
|
|
56
53
|
* @fires AggregationCursor#readable
|
|
57
54
|
* @return {AggregationCursor} an AggregationCursor instance.
|
|
58
55
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const bson = topology.s.bson;
|
|
64
|
-
const topologyOptions = topology.s.options;
|
|
65
|
-
|
|
66
|
-
// MaxTimeMS
|
|
67
|
-
var maxTimeMS = null;
|
|
68
|
-
|
|
69
|
-
// Get the promiseLibrary
|
|
70
|
-
var promiseLibrary = options.promiseLibrary || Promise;
|
|
71
|
-
|
|
72
|
-
// Set up
|
|
73
|
-
Readable.call(this, { objectMode: true });
|
|
74
|
-
|
|
75
|
-
// Internal state
|
|
76
|
-
this.s = {
|
|
77
|
-
// MaxTimeMS
|
|
78
|
-
maxTimeMS: maxTimeMS,
|
|
79
|
-
// State
|
|
80
|
-
state: state,
|
|
81
|
-
// Stream options
|
|
82
|
-
streamOptions: streamOptions,
|
|
83
|
-
// BSON
|
|
84
|
-
bson: bson,
|
|
85
|
-
// Namespace
|
|
86
|
-
// TODO: switch to raw namespace object later
|
|
87
|
-
namespace: MongoDBNamespace.fromString(ns),
|
|
88
|
-
// Command
|
|
89
|
-
cmd: cmd,
|
|
90
|
-
// Options
|
|
91
|
-
options: options,
|
|
92
|
-
// Topology
|
|
93
|
-
topology: topology,
|
|
94
|
-
// Topology Options
|
|
95
|
-
topologyOptions: topologyOptions,
|
|
96
|
-
// Promise library
|
|
97
|
-
promiseLibrary: promiseLibrary,
|
|
98
|
-
// Optional ClientSession
|
|
99
|
-
session: options.session
|
|
100
|
-
};
|
|
101
|
-
};
|
|
56
|
+
class AggregationCursor extends Cursor {
|
|
57
|
+
constructor(topology, operation, options) {
|
|
58
|
+
super(topology, operation, options);
|
|
59
|
+
}
|
|
102
60
|
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Set the batch size for the cursor.
|
|
63
|
+
* @method
|
|
64
|
+
* @param {number} value The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
|
|
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
|
+
}
|
|
109
81
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
}
|
|
116
92
|
|
|
117
|
-
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
}
|
|
123
103
|
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
+
}
|
|
130
114
|
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
}
|
|
133
125
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
}
|
|
143
136
|
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (typeof value !== 'number')
|
|
155
|
-
throw MongoError.create({ message: 'batchSize requires an integer', driver: true });
|
|
156
|
-
if (this.s.cmd.cursor) this.s.cmd.cursor.batchSize = value;
|
|
157
|
-
this.setCursorBatchSize(value);
|
|
158
|
-
return this;
|
|
159
|
-
};
|
|
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
|
+
}
|
|
160
147
|
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
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
|
+
}
|
|
171
158
|
|
|
172
|
-
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
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
|
+
}
|
|
182
169
|
|
|
183
|
-
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
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
|
+
}
|
|
193
180
|
|
|
194
|
-
/**
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
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
|
+
}
|
|
204
191
|
|
|
205
|
-
/**
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this
|
|
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;
|
|
214
201
|
}
|
|
215
|
-
return this;
|
|
216
|
-
};
|
|
217
202
|
|
|
218
|
-
/**
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
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
|
+
}
|
|
228
213
|
|
|
229
|
-
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
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
|
+
}
|
|
239
224
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
* @method
|
|
243
|
-
* @param {object} document The lookup stage document.
|
|
244
|
-
* @return {AggregationCursor}
|
|
245
|
-
*/
|
|
246
|
-
AggregationCursor.prototype.lookup = function(document) {
|
|
247
|
-
this.s.cmd.pipeline.push({ $lookup: document });
|
|
248
|
-
return this;
|
|
249
|
-
};
|
|
225
|
+
// aliases
|
|
226
|
+
AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
250
227
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
*/
|
|
257
|
-
AggregationCursor.prototype.redact = function(document) {
|
|
258
|
-
this.s.cmd.pipeline.push({ $redact: document });
|
|
259
|
-
return this;
|
|
260
|
-
};
|
|
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
|
+
);
|
|
261
233
|
|
|
262
234
|
/**
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* @
|
|
266
|
-
* @
|
|
235
|
+
* AggregationCursor stream data event, fired for each document in the cursor.
|
|
236
|
+
*
|
|
237
|
+
* @event AggregationCursor#data
|
|
238
|
+
* @type {object}
|
|
267
239
|
*/
|
|
268
|
-
AggregationCursor.prototype.skip = function(value) {
|
|
269
|
-
this.s.cmd.pipeline.push({ $skip: value });
|
|
270
|
-
return this;
|
|
271
|
-
};
|
|
272
240
|
|
|
273
241
|
/**
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* @
|
|
277
|
-
* @
|
|
242
|
+
* AggregationCursor stream end event
|
|
243
|
+
*
|
|
244
|
+
* @event AggregationCursor#end
|
|
245
|
+
* @type {null}
|
|
278
246
|
*/
|
|
279
|
-
AggregationCursor.prototype.sort = function(document) {
|
|
280
|
-
this.s.cmd.pipeline.push({ $sort: document });
|
|
281
|
-
return this;
|
|
282
|
-
};
|
|
283
247
|
|
|
284
248
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* @
|
|
288
|
-
* @
|
|
249
|
+
* AggregationCursor stream close event
|
|
250
|
+
*
|
|
251
|
+
* @event AggregationCursor#close
|
|
252
|
+
* @type {null}
|
|
289
253
|
*/
|
|
290
|
-
AggregationCursor.prototype.unwind = function(field) {
|
|
291
|
-
this.s.cmd.pipeline.push({ $unwind: field });
|
|
292
|
-
return this;
|
|
293
|
-
};
|
|
294
254
|
|
|
295
255
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
* @
|
|
299
|
-
* @
|
|
256
|
+
* AggregationCursor stream readable event
|
|
257
|
+
*
|
|
258
|
+
* @event AggregationCursor#readable
|
|
259
|
+
* @type {null}
|
|
300
260
|
*/
|
|
301
|
-
AggregationCursor.prototype.getLogger = function() {
|
|
302
|
-
return this.logger;
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
306
261
|
|
|
307
262
|
/**
|
|
308
263
|
* Get the next available document from the cursor, returns null if no more documents are available.
|
|
@@ -353,6 +308,7 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
|
353
308
|
* at any given time if batch size is specified. Otherwise, the caller is responsible
|
|
354
309
|
* for making sure that the entire result can fit the memory.
|
|
355
310
|
* @method AggregationCursor.prototype.each
|
|
311
|
+
* @deprecated
|
|
356
312
|
* @param {AggregationCursor~resultCallback} callback The result callback.
|
|
357
313
|
* @throws {MongoError}
|
|
358
314
|
* @return {null}
|
|
@@ -402,7 +358,7 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
|
402
358
|
* @param {MongoError} error An error instance representing the error during the execution.
|
|
403
359
|
*/
|
|
404
360
|
|
|
405
|
-
|
|
361
|
+
/**
|
|
406
362
|
* Iterates over all the documents for this cursor using the iterator, callback pattern.
|
|
407
363
|
* @method AggregationCursor.prototype.forEach
|
|
408
364
|
* @param {AggregationCursor~iteratorCallback} iterator The iteration callback.
|
|
@@ -411,8 +367,4 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
|
411
367
|
* @return {null}
|
|
412
368
|
*/
|
|
413
369
|
|
|
414
|
-
AggregationCursor.INIT = 0;
|
|
415
|
-
AggregationCursor.OPEN = 1;
|
|
416
|
-
AggregationCursor.CLOSED = 2;
|
|
417
|
-
|
|
418
370
|
module.exports = AggregationCursor;
|