mongodb 2.1.0-alpha → 2.1.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.
- package/HISTORY.md +574 -429
- package/Makefile +2 -5
- package/README.md +108 -15
- package/conf.json +17 -13
- package/index.js +13 -2
- package/lib/admin.js +113 -47
- package/lib/aggregation_cursor.js +56 -28
- package/lib/apm.js +608 -0
- package/lib/bulk/common.js +7 -7
- package/lib/bulk/ordered.js +56 -17
- package/lib/bulk/unordered.js +52 -14
- package/lib/collection.js +671 -212
- package/lib/command_cursor.js +60 -32
- package/lib/cursor.js +313 -115
- package/lib/db.js +264 -105
- package/lib/gridfs/chunk.js +26 -29
- package/lib/gridfs/grid_store.js +150 -64
- package/lib/gridfs-stream/download.js +310 -0
- package/lib/gridfs-stream/index.js +335 -0
- package/lib/gridfs-stream/upload.js +450 -0
- package/lib/metadata.js +64 -0
- package/lib/mongo_client.js +69 -39
- package/lib/mongos.js +65 -20
- package/lib/replset.js +69 -34
- package/lib/server.js +35 -1
- package/lib/topology_base.js +22 -10
- package/lib/url_parser.js +111 -13
- package/lib/utils.js +9 -8
- package/mongolabs.js +427 -0
- package/package.json +8 -6
- package/t.js +68 -51
- package/test.js +12 -0
- package/test_boot/boot.sh +3 -0
- package/test_boot/ca.pem +49 -0
- package/test_boot/client.pem +48 -0
- package/test_boot/client_password.pem +51 -0
- package/test_boot/connect.js +29 -0
- package/test_boot/data/WiredTiger +2 -0
- package/test_boot/data/WiredTiger.lock +1 -0
- package/test_boot/data/WiredTiger.turtle +6 -0
- package/test_boot/data/WiredTiger.wt +0 -0
- package/test_boot/data/WiredTigerLAS.wt +0 -0
- package/test_boot/data/_mdb_catalog.wt +0 -0
- package/test_boot/data/collection-0-757073248613337118.wt +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-44-37Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-45-15Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-46-31Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-47-25Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-49-07Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-50-41Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-50-53Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-52-31Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-54-53Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-55-09Z-00000 +0 -0
- package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-55-38Z-00000 +0 -0
- package/test_boot/data/index-1-757073248613337118.wt +0 -0
- package/test_boot/data/mongod.lock +0 -0
- package/test_boot/data/sizeStorer.wt +0 -0
- package/test_boot/data/storage.bson +0 -0
- package/test_boot/server_password.pem +51 -0
- package/.travis.yml +0 -10
- package/t1.js +0 -59
- package/wercker.yml +0 -19
package/lib/admin.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var toError = require('./utils').toError
|
|
3
|
+
var toError = require('./utils').toError,
|
|
4
|
+
Define = require('./metadata'),
|
|
5
|
+
shallowClone = require('./utils').shallowClone;
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @fileOverview The **Admin** class is an internal class that allows convenient access to
|
|
7
9
|
* the admin functionality and commands for MongoDB.
|
|
8
|
-
*
|
|
10
|
+
*
|
|
9
11
|
* **ADMIN Cannot directly be instantiated**
|
|
10
12
|
* @example
|
|
11
13
|
* var MongoClient = require('mongodb').MongoClient,
|
|
@@ -16,7 +18,7 @@ var toError = require('./utils').toError;
|
|
|
16
18
|
* MongoClient.connect(url, function(err, db) {
|
|
17
19
|
* // Use the admin database for the operation
|
|
18
20
|
* var adminDb = db.admin();
|
|
19
|
-
*
|
|
21
|
+
*
|
|
20
22
|
* // List all the available databases
|
|
21
23
|
* adminDb.listDatabases(function(err, dbs) {
|
|
22
24
|
* test.equal(null, err);
|
|
@@ -43,6 +45,8 @@ var Admin = function(db, topology, promiseLibrary) {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
var define = Admin.define = new Define('Admin', Admin, false);
|
|
49
|
+
|
|
46
50
|
/**
|
|
47
51
|
* The callback format for results
|
|
48
52
|
* @callback Admin~resultCallback
|
|
@@ -57,7 +61,7 @@ var Admin = function(db, topology, promiseLibrary) {
|
|
|
57
61
|
* @param {object} [options=null] Optional settings.
|
|
58
62
|
* @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
|
59
63
|
* @param {number} [options.maxTimeMS=null] Number of milliseconds to wait before aborting the query.
|
|
60
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
64
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
61
65
|
* @return {Promise} returns Promise if no callback passed
|
|
62
66
|
*/
|
|
63
67
|
Admin.prototype.command = function(command, options, callback) {
|
|
@@ -79,14 +83,15 @@ Admin.prototype.command = function(command, options, callback) {
|
|
|
79
83
|
resolve(doc);
|
|
80
84
|
});
|
|
81
85
|
});
|
|
86
|
+
}
|
|
82
87
|
|
|
83
|
-
}
|
|
88
|
+
define.classMethod('command', {callback: true, promise:true});
|
|
84
89
|
|
|
85
90
|
/**
|
|
86
91
|
* Retrieve the server information for the current
|
|
87
92
|
* instance of the db client
|
|
88
93
|
*
|
|
89
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
94
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
90
95
|
* @return {Promise} returns Promise if no callback passed
|
|
91
96
|
*/
|
|
92
97
|
Admin.prototype.buildInfo = function(callback) {
|
|
@@ -98,16 +103,18 @@ Admin.prototype.buildInfo = function(callback) {
|
|
|
98
103
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
99
104
|
self.serverInfo(function(err, r) {
|
|
100
105
|
if(err) return reject(err);
|
|
101
|
-
resolve(r);
|
|
106
|
+
resolve(r);
|
|
102
107
|
});
|
|
103
108
|
});
|
|
104
109
|
}
|
|
105
110
|
|
|
111
|
+
define.classMethod('buildInfo', {callback: true, promise:true});
|
|
112
|
+
|
|
106
113
|
/**
|
|
107
114
|
* Retrieve the server information for the current
|
|
108
115
|
* instance of the db client
|
|
109
116
|
*
|
|
110
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
117
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
111
118
|
* @return {Promise} returns Promise if no callback passed
|
|
112
119
|
*/
|
|
113
120
|
Admin.prototype.serverInfo = function(callback) {
|
|
@@ -127,10 +134,12 @@ Admin.prototype.serverInfo = function(callback) {
|
|
|
127
134
|
});
|
|
128
135
|
}
|
|
129
136
|
|
|
137
|
+
define.classMethod('serverInfo', {callback: true, promise:true});
|
|
138
|
+
|
|
130
139
|
/**
|
|
131
140
|
* Retrieve this db's server status.
|
|
132
141
|
*
|
|
133
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
142
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
134
143
|
* @return {Promise} returns Promise if no callback passed
|
|
135
144
|
*/
|
|
136
145
|
Admin.prototype.serverStatus = function(callback) {
|
|
@@ -143,7 +152,7 @@ Admin.prototype.serverStatus = function(callback) {
|
|
|
143
152
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
144
153
|
serverStatus(self, function(err, r) {
|
|
145
154
|
if(err) return reject(err);
|
|
146
|
-
resolve(r);
|
|
155
|
+
resolve(r);
|
|
147
156
|
});
|
|
148
157
|
});
|
|
149
158
|
};
|
|
@@ -156,13 +165,15 @@ var serverStatus = function(self, callback) {
|
|
|
156
165
|
if(err) return callback(err, false);
|
|
157
166
|
return callback(toError(doc), false);
|
|
158
167
|
}
|
|
159
|
-
});
|
|
168
|
+
});
|
|
160
169
|
}
|
|
161
170
|
|
|
171
|
+
define.classMethod('serverStatus', {callback: true, promise:true});
|
|
172
|
+
|
|
162
173
|
/**
|
|
163
174
|
* Retrieve the current profiling Level for MongoDB
|
|
164
175
|
*
|
|
165
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
176
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
166
177
|
* @return {Promise} returns Promise if no callback passed
|
|
167
178
|
*/
|
|
168
179
|
Admin.prototype.profilingLevel = function(callback) {
|
|
@@ -175,7 +186,7 @@ Admin.prototype.profilingLevel = function(callback) {
|
|
|
175
186
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
176
187
|
profilingLevel(self, function(err, r) {
|
|
177
188
|
if(err) return reject(err);
|
|
178
|
-
resolve(r);
|
|
189
|
+
resolve(r);
|
|
179
190
|
});
|
|
180
191
|
});
|
|
181
192
|
};
|
|
@@ -196,10 +207,12 @@ var profilingLevel = function(self, callback) {
|
|
|
196
207
|
});
|
|
197
208
|
}
|
|
198
209
|
|
|
210
|
+
define.classMethod('profilingLevel', {callback: true, promise:true});
|
|
211
|
+
|
|
199
212
|
/**
|
|
200
213
|
* Ping the MongoDB server and retrieve results
|
|
201
214
|
*
|
|
202
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
215
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
203
216
|
* @return {Promise} returns Promise if no callback passed
|
|
204
217
|
*/
|
|
205
218
|
Admin.prototype.ping = function(options, callback) {
|
|
@@ -215,37 +228,45 @@ Admin.prototype.ping = function(options, callback) {
|
|
|
215
228
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
216
229
|
self.s.db.executeDbAdminCommand({ping: 1}, function(err, r) {
|
|
217
230
|
if(err) return reject(err);
|
|
218
|
-
resolve(r);
|
|
231
|
+
resolve(r);
|
|
219
232
|
});
|
|
220
233
|
});
|
|
221
234
|
}
|
|
222
235
|
|
|
236
|
+
define.classMethod('ping', {callback: true, promise:true});
|
|
237
|
+
|
|
223
238
|
/**
|
|
224
239
|
* Authenticate a user against the server.
|
|
225
240
|
* @method
|
|
226
241
|
* @param {string} username The username.
|
|
227
242
|
* @param {string} [password] The password.
|
|
228
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
243
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
229
244
|
* @return {Promise} returns Promise if no callback passed
|
|
230
245
|
*/
|
|
231
|
-
Admin.prototype.authenticate = function(username, password, callback) {
|
|
246
|
+
Admin.prototype.authenticate = function(username, password, options, callback) {
|
|
232
247
|
var self = this;
|
|
248
|
+
if(typeof options == 'function') callback = options, options = {};
|
|
249
|
+
options = shallowClone(options);
|
|
250
|
+
options.authdb = 'admin';
|
|
251
|
+
|
|
233
252
|
// Execute using callback
|
|
234
|
-
if(typeof callback == 'function') return this.s.db.authenticate(username, password,
|
|
253
|
+
if(typeof callback == 'function') return this.s.db.authenticate(username, password, options, callback);
|
|
235
254
|
|
|
236
255
|
// Return a Promise
|
|
237
256
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
238
|
-
self.s.db.authenticate(username, password,
|
|
257
|
+
self.s.db.authenticate(username, password, options, function(err, r) {
|
|
239
258
|
if(err) return reject(err);
|
|
240
|
-
resolve(r);
|
|
259
|
+
resolve(r);
|
|
241
260
|
});
|
|
242
|
-
});
|
|
261
|
+
});
|
|
243
262
|
}
|
|
244
263
|
|
|
264
|
+
define.classMethod('authenticate', {callback: true, promise:true});
|
|
265
|
+
|
|
245
266
|
/**
|
|
246
267
|
* Logout user from server, fire off on all connections and remove all auth info
|
|
247
268
|
* @method
|
|
248
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
269
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
249
270
|
* @return {Promise} returns Promise if no callback passed
|
|
250
271
|
*/
|
|
251
272
|
Admin.prototype.logout = function(callback) {
|
|
@@ -257,11 +278,34 @@ Admin.prototype.logout = function(callback) {
|
|
|
257
278
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
258
279
|
self.s.db.logout({authdb: 'admin'}, function(err, r) {
|
|
259
280
|
if(err) return reject(err);
|
|
260
|
-
resolve(r);
|
|
281
|
+
resolve(r);
|
|
261
282
|
});
|
|
262
283
|
});
|
|
263
284
|
}
|
|
264
285
|
|
|
286
|
+
define.classMethod('logout', {callback: true, promise:true});
|
|
287
|
+
|
|
288
|
+
// Get write concern
|
|
289
|
+
var writeConcern = function(options, db) {
|
|
290
|
+
options = shallowClone(options);
|
|
291
|
+
|
|
292
|
+
// If options already contain write concerns return it
|
|
293
|
+
if(options.w || options.wtimeout || options.j || options.fsync) {
|
|
294
|
+
return options;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Set db write concern if available
|
|
298
|
+
if(db.writeConcern) {
|
|
299
|
+
if(options.w) options.w = db.writeConcern.w;
|
|
300
|
+
if(options.wtimeout) options.wtimeout = db.writeConcern.wtimeout;
|
|
301
|
+
if(options.j) options.j = db.writeConcern.j;
|
|
302
|
+
if(options.fsync) options.fsync = db.writeConcern.fsync;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Return modified options
|
|
306
|
+
return options;
|
|
307
|
+
}
|
|
308
|
+
|
|
265
309
|
/**
|
|
266
310
|
* Add a user to the database.
|
|
267
311
|
* @method
|
|
@@ -274,7 +318,7 @@ Admin.prototype.logout = function(callback) {
|
|
|
274
318
|
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
275
319
|
* @param {object} [options.customData=null] Custom data associated with the user (only Mongodb 2.6 or higher)
|
|
276
320
|
* @param {object[]} [options.roles=null] Roles associated with the created user (only Mongodb 2.6 or higher)
|
|
277
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
321
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
278
322
|
* @return {Promise} returns Promise if no callback passed
|
|
279
323
|
*/
|
|
280
324
|
Admin.prototype.addUser = function(username, password, options, callback) {
|
|
@@ -284,21 +328,26 @@ Admin.prototype.addUser = function(username, password, options, callback) {
|
|
|
284
328
|
if(typeof callback != 'function') args.push(callback);
|
|
285
329
|
options = args.length ? args.shift() : {};
|
|
286
330
|
options = options || {};
|
|
331
|
+
// Get the options
|
|
332
|
+
options = writeConcern(options, self.s.db)
|
|
287
333
|
// Set the db name to admin
|
|
288
334
|
options.dbName = 'admin';
|
|
289
335
|
|
|
290
336
|
// Execute using callback
|
|
291
|
-
if(typeof callback == 'function')
|
|
337
|
+
if(typeof callback == 'function')
|
|
338
|
+
return self.s.db.addUser(username, password, options, callback);
|
|
292
339
|
|
|
293
340
|
// Return a Promise
|
|
294
341
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
295
342
|
self.s.db.addUser(username, password, options, function(err, r) {
|
|
296
343
|
if(err) return reject(err);
|
|
297
|
-
resolve(r);
|
|
344
|
+
resolve(r);
|
|
298
345
|
});
|
|
299
346
|
});
|
|
300
347
|
}
|
|
301
348
|
|
|
349
|
+
define.classMethod('addUser', {callback: true, promise:true});
|
|
350
|
+
|
|
302
351
|
/**
|
|
303
352
|
* Remove a user from a database
|
|
304
353
|
* @method
|
|
@@ -308,7 +357,7 @@ Admin.prototype.addUser = function(username, password, options, callback) {
|
|
|
308
357
|
* @param {number} [options.wtimeout=null] The write concern timeout.
|
|
309
358
|
* @param {boolean} [options.j=false] Specify a journal write concern.
|
|
310
359
|
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
|
|
311
|
-
* @param {Admin~resultCallback} callback The command result callback
|
|
360
|
+
* @param {Admin~resultCallback} [callback] The command result callback
|
|
312
361
|
* @return {Promise} returns Promise if no callback passed
|
|
313
362
|
*/
|
|
314
363
|
Admin.prototype.removeUser = function(username, options, callback) {
|
|
@@ -318,25 +367,31 @@ Admin.prototype.removeUser = function(username, options, callback) {
|
|
|
318
367
|
if(typeof callback != 'function') args.push(callback);
|
|
319
368
|
options = args.length ? args.shift() : {};
|
|
320
369
|
options = options || {};
|
|
370
|
+
// Get the options
|
|
371
|
+
options = writeConcern(options, self.s.db)
|
|
372
|
+
// Set the db name
|
|
321
373
|
options.dbName = 'admin';
|
|
322
374
|
|
|
323
375
|
// Execute using callback
|
|
324
|
-
if(typeof callback == 'function')
|
|
376
|
+
if(typeof callback == 'function')
|
|
377
|
+
return self.s.db.removeUser(username, options, callback);
|
|
325
378
|
|
|
326
379
|
// Return a Promise
|
|
327
380
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
328
381
|
self.s.db.removeUser(username, options, function(err, r) {
|
|
329
382
|
if(err) return reject(err);
|
|
330
|
-
resolve(r);
|
|
383
|
+
resolve(r);
|
|
331
384
|
});
|
|
332
385
|
});
|
|
333
386
|
}
|
|
334
387
|
|
|
388
|
+
define.classMethod('removeUser', {callback: true, promise:true});
|
|
389
|
+
|
|
335
390
|
/**
|
|
336
391
|
* Set the current profiling level of MongoDB
|
|
337
392
|
*
|
|
338
393
|
* @param {string} level The new profiling level (off, slow_only, all).
|
|
339
|
-
* @param {Admin~resultCallback} callback The command result callback.
|
|
394
|
+
* @param {Admin~resultCallback} [callback] The command result callback.
|
|
340
395
|
* @return {Promise} returns Promise if no callback passed
|
|
341
396
|
*/
|
|
342
397
|
Admin.prototype.setProfilingLevel = function(level, callback) {
|
|
@@ -349,7 +404,7 @@ Admin.prototype.setProfilingLevel = function(level, callback) {
|
|
|
349
404
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
350
405
|
setProfilingLevel(self, level, function(err, r) {
|
|
351
406
|
if(err) return reject(err);
|
|
352
|
-
resolve(r);
|
|
407
|
+
resolve(r);
|
|
353
408
|
});
|
|
354
409
|
});
|
|
355
410
|
};
|
|
@@ -377,13 +432,15 @@ var setProfilingLevel = function(self, level, callback) {
|
|
|
377
432
|
if(err == null && doc.ok === 1)
|
|
378
433
|
return callback(null, level);
|
|
379
434
|
return err != null ? callback(err, null) : callback(new Error("Error with profile command"), null);
|
|
380
|
-
});
|
|
435
|
+
});
|
|
381
436
|
}
|
|
382
437
|
|
|
438
|
+
define.classMethod('setProfilingLevel', {callback: true, promise:true});
|
|
439
|
+
|
|
383
440
|
/**
|
|
384
441
|
* Retrive the current profiling information for MongoDB
|
|
385
442
|
*
|
|
386
|
-
* @param {Admin~resultCallback} callback The command result callback.
|
|
443
|
+
* @param {Admin~resultCallback} [callback] The command result callback.
|
|
387
444
|
* @return {Promise} returns Promise if no callback passed
|
|
388
445
|
*/
|
|
389
446
|
Admin.prototype.profilingInfo = function(callback) {
|
|
@@ -396,7 +453,7 @@ Admin.prototype.profilingInfo = function(callback) {
|
|
|
396
453
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
397
454
|
profilingInfo(self, function(err, r) {
|
|
398
455
|
if(err) return reject(err);
|
|
399
|
-
resolve(r);
|
|
456
|
+
resolve(r);
|
|
400
457
|
});
|
|
401
458
|
});
|
|
402
459
|
};
|
|
@@ -406,15 +463,17 @@ var profilingInfo = function(self, callback) {
|
|
|
406
463
|
self.s.topology.cursor("admin.system.profile", { find: 'system.profile', query: {}}, {}).toArray(callback);
|
|
407
464
|
} catch (err) {
|
|
408
465
|
return callback(err, null);
|
|
409
|
-
}
|
|
466
|
+
}
|
|
410
467
|
}
|
|
411
468
|
|
|
469
|
+
define.classMethod('profilingLevel', {callback: true, promise:true});
|
|
470
|
+
|
|
412
471
|
/**
|
|
413
472
|
* Validate an existing collection
|
|
414
473
|
*
|
|
415
474
|
* @param {string} collectionName The name of the collection to validate.
|
|
416
475
|
* @param {object} [options=null] Optional settings.
|
|
417
|
-
* @param {Admin~resultCallback} callback The command result callback.
|
|
476
|
+
* @param {Admin~resultCallback} [callback] The command result callback.
|
|
418
477
|
* @return {Promise} returns Promise if no callback passed
|
|
419
478
|
*/
|
|
420
479
|
Admin.prototype.validateCollection = function(collectionName, options, callback) {
|
|
@@ -426,13 +485,14 @@ Admin.prototype.validateCollection = function(collectionName, options, callback)
|
|
|
426
485
|
options = options || {};
|
|
427
486
|
|
|
428
487
|
// Execute using callback
|
|
429
|
-
if(typeof callback == 'function')
|
|
488
|
+
if(typeof callback == 'function')
|
|
489
|
+
return validateCollection(self, collectionName, options, callback);
|
|
430
490
|
|
|
431
491
|
// Return a Promise
|
|
432
492
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
433
493
|
validateCollection(self, collectionName, options, function(err, r) {
|
|
434
494
|
if(err) return reject(err);
|
|
435
|
-
resolve(r);
|
|
495
|
+
resolve(r);
|
|
436
496
|
});
|
|
437
497
|
});
|
|
438
498
|
};
|
|
@@ -461,13 +521,15 @@ var validateCollection = function(self, collectionName, options, callback) {
|
|
|
461
521
|
return callback(new Error("Error: invalid collection " + collectionName), null);
|
|
462
522
|
|
|
463
523
|
return callback(null, doc);
|
|
464
|
-
});
|
|
524
|
+
});
|
|
465
525
|
}
|
|
466
526
|
|
|
527
|
+
define.classMethod('validateCollection', {callback: true, promise:true});
|
|
528
|
+
|
|
467
529
|
/**
|
|
468
530
|
* List the available databases
|
|
469
531
|
*
|
|
470
|
-
* @param {Admin~resultCallback} callback The command result callback.
|
|
532
|
+
* @param {Admin~resultCallback} [callback] The command result callback.
|
|
471
533
|
* @return {Promise} returns Promise if no callback passed
|
|
472
534
|
*/
|
|
473
535
|
Admin.prototype.listDatabases = function(callback) {
|
|
@@ -479,15 +541,17 @@ Admin.prototype.listDatabases = function(callback) {
|
|
|
479
541
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
480
542
|
self.s.db.executeDbAdminCommand({listDatabases:1}, {}, function(err, r) {
|
|
481
543
|
if(err) return reject(err);
|
|
482
|
-
resolve(r);
|
|
544
|
+
resolve(r);
|
|
483
545
|
});
|
|
484
|
-
});
|
|
546
|
+
});
|
|
485
547
|
}
|
|
486
548
|
|
|
549
|
+
define.classMethod('listDatabases', {callback: true, promise:true});
|
|
550
|
+
|
|
487
551
|
/**
|
|
488
552
|
* Get ReplicaSet status
|
|
489
553
|
*
|
|
490
|
-
* @param {Admin~resultCallback} callback The command result callback.
|
|
554
|
+
* @param {Admin~resultCallback} [callback] The command result callback.
|
|
491
555
|
* @return {Promise} returns Promise if no callback passed
|
|
492
556
|
*/
|
|
493
557
|
Admin.prototype.replSetGetStatus = function(callback) {
|
|
@@ -498,10 +562,10 @@ Admin.prototype.replSetGetStatus = function(callback) {
|
|
|
498
562
|
return new this.s.promiseLibrary(function(resolve, reject) {
|
|
499
563
|
replSetGetStatus(self, function(err, r) {
|
|
500
564
|
if(err) return reject(err);
|
|
501
|
-
resolve(r);
|
|
565
|
+
resolve(r);
|
|
502
566
|
});
|
|
503
567
|
});
|
|
504
|
-
};
|
|
568
|
+
};
|
|
505
569
|
|
|
506
570
|
var replSetGetStatus = function(self, callback) {
|
|
507
571
|
self.s.db.executeDbAdminCommand({replSetGetStatus:1}, function(err, doc) {
|
|
@@ -509,7 +573,9 @@ var replSetGetStatus = function(self, callback) {
|
|
|
509
573
|
return callback(null, doc);
|
|
510
574
|
if(err) return callback(err, false);
|
|
511
575
|
callback(toError(doc), false);
|
|
512
|
-
});
|
|
576
|
+
});
|
|
513
577
|
}
|
|
514
578
|
|
|
515
|
-
|
|
579
|
+
define.classMethod('replSetGetStatus', {callback: true, promise:true});
|
|
580
|
+
|
|
581
|
+
module.exports = Admin;
|
|
@@ -11,6 +11,7 @@ var inherits = require('util').inherits
|
|
|
11
11
|
, ReadPreference = require('./read_preference')
|
|
12
12
|
, MongoError = require('mongodb-core').MongoError
|
|
13
13
|
, Readable = require('stream').Readable || require('readable-stream').Readable
|
|
14
|
+
, Define = require('./metadata')
|
|
14
15
|
, CoreCursor = require('./cursor')
|
|
15
16
|
, Query = require('mongodb-core').Query
|
|
16
17
|
, CoreReadPreference = require('mongodb-core').ReadPreference;
|
|
@@ -18,9 +19,9 @@ var inherits = require('util').inherits
|
|
|
18
19
|
/**
|
|
19
20
|
* @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
|
|
20
21
|
* allowing for iteration over the results returned from the underlying query. It supports
|
|
21
|
-
* one by one document iteration, conversion to an array or can be iterated as a Node 0.10.X
|
|
22
|
+
* one by one document iteration, conversion to an array or can be iterated as a Node 0.10.X
|
|
22
23
|
* or higher stream
|
|
23
|
-
*
|
|
24
|
+
*
|
|
24
25
|
* **AGGREGATIONCURSOR Cannot directly be instantiated**
|
|
25
26
|
* @example
|
|
26
27
|
* var MongoClient = require('mongodb').MongoClient,
|
|
@@ -36,7 +37,6 @@ var inherits = require('util').inherits
|
|
|
36
37
|
* , {a:2, b:2}, {a:3, b:3}
|
|
37
38
|
* , {a:4, b:4}], {w:1}, function(err, result) {
|
|
38
39
|
* test.equal(null, err);
|
|
39
|
-
*
|
|
40
40
|
* // Show that duplicate records got dropped
|
|
41
41
|
* col.aggregation({}, {cursor: {}}).toArray(function(err, items) {
|
|
42
42
|
* test.equal(null, err);
|
|
@@ -104,7 +104,7 @@ var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptio
|
|
|
104
104
|
// Topology Options
|
|
105
105
|
, topologyOptions: topologyOptions
|
|
106
106
|
// Promise library
|
|
107
|
-
, promiseLibrary: promiseLibrary
|
|
107
|
+
, promiseLibrary: promiseLibrary
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -137,13 +137,20 @@ var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptio
|
|
|
137
137
|
*/
|
|
138
138
|
|
|
139
139
|
// Inherit from Readable
|
|
140
|
-
inherits(AggregationCursor, Readable);
|
|
140
|
+
inherits(AggregationCursor, Readable);
|
|
141
|
+
|
|
142
|
+
// Set the methods to inherit from prototype
|
|
143
|
+
var methodsToInherit = ['_next', 'next', 'each', 'forEach', 'toArray'
|
|
144
|
+
, 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed', 'kill'
|
|
145
|
+
, '_find', '_getmore', '_killcursor', 'isDead', 'explain', 'isNotified'];
|
|
141
146
|
|
|
142
147
|
// Extend the Cursor
|
|
143
148
|
for(var name in CoreCursor.prototype) {
|
|
144
149
|
AggregationCursor.prototype[name] = CoreCursor.prototype[name];
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
var define = AggregationCursor.define = new Define('AggregationCursor', AggregationCursor, true);
|
|
153
|
+
|
|
147
154
|
/**
|
|
148
155
|
* Set the batch size for the cursor.
|
|
149
156
|
* @method
|
|
@@ -152,13 +159,15 @@ for(var name in CoreCursor.prototype) {
|
|
|
152
159
|
* @return {AggregationCursor}
|
|
153
160
|
*/
|
|
154
161
|
AggregationCursor.prototype.batchSize = function(value) {
|
|
155
|
-
if(this.s.state == AggregationCursor.CLOSED || this.isDead()) throw
|
|
156
|
-
if(typeof value != 'number') throw
|
|
162
|
+
if(this.s.state == AggregationCursor.CLOSED || this.isDead()) throw MongoError.create({message: "Cursor is closed", driver:true });
|
|
163
|
+
if(typeof value != 'number') throw MongoError.create({message: "batchSize requires an integer", drvier:true });
|
|
157
164
|
if(this.s.cmd.cursor) this.s.cmd.cursor.batchSize = value;
|
|
158
165
|
this.setCursorBatchSize(value);
|
|
159
166
|
return this;
|
|
160
167
|
}
|
|
161
168
|
|
|
169
|
+
define.classMethod('batchSize', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
170
|
+
|
|
162
171
|
/**
|
|
163
172
|
* Add a geoNear stage to the aggregation pipeline
|
|
164
173
|
* @method
|
|
@@ -170,6 +179,8 @@ AggregationCursor.prototype.geoNear = function(document) {
|
|
|
170
179
|
return this;
|
|
171
180
|
}
|
|
172
181
|
|
|
182
|
+
define.classMethod('geoNear', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
183
|
+
|
|
173
184
|
/**
|
|
174
185
|
* Add a group stage to the aggregation pipeline
|
|
175
186
|
* @method
|
|
@@ -181,6 +192,8 @@ AggregationCursor.prototype.group = function(document) {
|
|
|
181
192
|
return this;
|
|
182
193
|
}
|
|
183
194
|
|
|
195
|
+
define.classMethod('group', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
196
|
+
|
|
184
197
|
/**
|
|
185
198
|
* Add a limit stage to the aggregation pipeline
|
|
186
199
|
* @method
|
|
@@ -192,6 +205,8 @@ AggregationCursor.prototype.limit = function(value) {
|
|
|
192
205
|
return this;
|
|
193
206
|
}
|
|
194
207
|
|
|
208
|
+
define.classMethod('limit', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
209
|
+
|
|
195
210
|
/**
|
|
196
211
|
* Add a match stage to the aggregation pipeline
|
|
197
212
|
* @method
|
|
@@ -203,6 +218,8 @@ AggregationCursor.prototype.match = function(document) {
|
|
|
203
218
|
return this;
|
|
204
219
|
}
|
|
205
220
|
|
|
221
|
+
define.classMethod('match', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
222
|
+
|
|
206
223
|
/**
|
|
207
224
|
* Add a maxTimeMS stage to the aggregation pipeline
|
|
208
225
|
* @method
|
|
@@ -216,6 +233,8 @@ AggregationCursor.prototype.maxTimeMS = function(value) {
|
|
|
216
233
|
return this;
|
|
217
234
|
}
|
|
218
235
|
|
|
236
|
+
define.classMethod('maxTimeMS', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
237
|
+
|
|
219
238
|
/**
|
|
220
239
|
* Add a out stage to the aggregation pipeline
|
|
221
240
|
* @method
|
|
@@ -227,6 +246,8 @@ AggregationCursor.prototype.out = function(destination) {
|
|
|
227
246
|
return this;
|
|
228
247
|
}
|
|
229
248
|
|
|
249
|
+
define.classMethod('out', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
250
|
+
|
|
230
251
|
/**
|
|
231
252
|
* Add a project stage to the aggregation pipeline
|
|
232
253
|
* @method
|
|
@@ -238,6 +259,8 @@ AggregationCursor.prototype.project = function(document) {
|
|
|
238
259
|
return this;
|
|
239
260
|
}
|
|
240
261
|
|
|
262
|
+
define.classMethod('project', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
263
|
+
|
|
241
264
|
/**
|
|
242
265
|
* Add a redact stage to the aggregation pipeline
|
|
243
266
|
* @method
|
|
@@ -249,6 +272,8 @@ AggregationCursor.prototype.redact = function(document) {
|
|
|
249
272
|
return this;
|
|
250
273
|
}
|
|
251
274
|
|
|
275
|
+
define.classMethod('redact', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
276
|
+
|
|
252
277
|
/**
|
|
253
278
|
* Add a skip stage to the aggregation pipeline
|
|
254
279
|
* @method
|
|
@@ -260,6 +285,8 @@ AggregationCursor.prototype.skip = function(value) {
|
|
|
260
285
|
return this;
|
|
261
286
|
}
|
|
262
287
|
|
|
288
|
+
define.classMethod('skip', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
289
|
+
|
|
263
290
|
/**
|
|
264
291
|
* Add a sort stage to the aggregation pipeline
|
|
265
292
|
* @method
|
|
@@ -271,6 +298,8 @@ AggregationCursor.prototype.sort = function(document) {
|
|
|
271
298
|
return this;
|
|
272
299
|
}
|
|
273
300
|
|
|
301
|
+
define.classMethod('sort', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
302
|
+
|
|
274
303
|
/**
|
|
275
304
|
* Add a unwind stage to the aggregation pipeline
|
|
276
305
|
* @method
|
|
@@ -282,30 +311,29 @@ AggregationCursor.prototype.unwind = function(field) {
|
|
|
282
311
|
return this;
|
|
283
312
|
}
|
|
284
313
|
|
|
314
|
+
define.classMethod('unwind', {callback: false, promise:false, returns: [AggregationCursor]});
|
|
315
|
+
|
|
285
316
|
AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
286
317
|
|
|
318
|
+
// Inherited methods
|
|
319
|
+
define.classMethod('toArray', {callback: true, promise:true});
|
|
320
|
+
define.classMethod('each', {callback: true, promise:false});
|
|
321
|
+
define.classMethod('forEach', {callback: true, promise:false});
|
|
322
|
+
define.classMethod('next', {callback: true, promise:true});
|
|
323
|
+
define.classMethod('close', {callback: true, promise:true});
|
|
324
|
+
define.classMethod('isClosed', {callback: false, promise:false, returns: [Boolean]});
|
|
325
|
+
define.classMethod('rewind', {callback: false, promise:false});
|
|
326
|
+
define.classMethod('bufferedCount', {callback: false, promise:false, returns: [Number]});
|
|
327
|
+
define.classMethod('readBufferedDocuments', {callback: false, promise:false, returns: [Array]});
|
|
328
|
+
|
|
287
329
|
/**
|
|
288
330
|
* Get the next available document from the cursor, returns null if no more documents are available.
|
|
289
331
|
* @function AggregationCursor.prototype.next
|
|
290
|
-
* @param {AggregationCursor~resultCallback} callback The result callback.
|
|
332
|
+
* @param {AggregationCursor~resultCallback} [callback] The result callback.
|
|
291
333
|
* @throws {MongoError}
|
|
292
334
|
* @return {Promise} returns Promise if no callback passed
|
|
293
335
|
*/
|
|
294
336
|
|
|
295
|
-
/**
|
|
296
|
-
* Set the new batchSize of the cursor
|
|
297
|
-
* @function AggregationCursor.prototype.setBatchSize
|
|
298
|
-
* @param {number} value The new batchSize for the cursor
|
|
299
|
-
* @return {null}
|
|
300
|
-
*/
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Get the batchSize of the cursor
|
|
304
|
-
* @function AggregationCursor.prototype.batchSize
|
|
305
|
-
* @param {number} value The current batchSize for the cursor
|
|
306
|
-
* @return {null}
|
|
307
|
-
*/
|
|
308
|
-
|
|
309
337
|
/**
|
|
310
338
|
* The callback format for results
|
|
311
339
|
* @callback AggregationCursor~toArrayResultCallback
|
|
@@ -319,7 +347,7 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
|
319
347
|
* results when this cursor had been previouly accessed. In that case,
|
|
320
348
|
* cursor.rewind() can be used to reset the cursor.
|
|
321
349
|
* @method AggregationCursor.prototype.toArray
|
|
322
|
-
* @param {AggregationCursor~toArrayResultCallback} callback The result callback.
|
|
350
|
+
* @param {AggregationCursor~toArrayResultCallback} [callback] The result callback.
|
|
323
351
|
* @throws {MongoError}
|
|
324
352
|
* @return {Promise} returns Promise if no callback passed
|
|
325
353
|
*/
|
|
@@ -349,13 +377,13 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
|
349
377
|
* @method AggregationCursor.prototype.close
|
|
350
378
|
* @param {AggregationCursor~resultCallback} [callback] The result callback.
|
|
351
379
|
* @return {Promise} returns Promise if no callback passed
|
|
352
|
-
*/
|
|
380
|
+
*/
|
|
353
381
|
|
|
354
382
|
/**
|
|
355
383
|
* Is the cursor closed
|
|
356
384
|
* @method AggregationCursor.prototype.isClosed
|
|
357
385
|
* @return {boolean}
|
|
358
|
-
*/
|
|
386
|
+
*/
|
|
359
387
|
|
|
360
388
|
/**
|
|
361
389
|
* Execute the explain for the cursor
|
|
@@ -368,13 +396,13 @@ AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
|
|
|
368
396
|
* Clone the cursor
|
|
369
397
|
* @function AggregationCursor.prototype.clone
|
|
370
398
|
* @return {AggregationCursor}
|
|
371
|
-
*/
|
|
399
|
+
*/
|
|
372
400
|
|
|
373
401
|
/**
|
|
374
402
|
* Resets the cursor
|
|
375
403
|
* @function AggregationCursor.prototype.rewind
|
|
376
404
|
* @return {AggregationCursor}
|
|
377
|
-
*/
|
|
405
|
+
*/
|
|
378
406
|
|
|
379
407
|
/**
|
|
380
408
|
* The callback format for the forEach iterator method
|
|
@@ -401,4 +429,4 @@ AggregationCursor.INIT = 0;
|
|
|
401
429
|
AggregationCursor.OPEN = 1;
|
|
402
430
|
AggregationCursor.CLOSED = 2;
|
|
403
431
|
|
|
404
|
-
module.exports = AggregationCursor;
|
|
432
|
+
module.exports = AggregationCursor;
|