mongodb 2.2.29 → 2.2.33

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 CHANGED
@@ -1,3 +1,30 @@
1
+ 2.2.33 2017-10-12
2
+ -----------------
3
+ * update to mongodb-core 2.1.17
4
+
5
+ 2.2.32 2017-10-11
6
+ -----------------
7
+ * update to mongodb-core 2.1.16
8
+ * ensure that the `cursor` key is always present in aggregation commands
9
+ * `Cursor.prototype.hasNext` now propagates errors when using callback
10
+ * allow passing `noCursorTimeout` as an option to `find()`
11
+ * bubble up `reconnectFailed` event from Server topology
12
+
13
+ 2.2.31 2017-08-08
14
+ -----------------
15
+ * update mongodb-core to 2.1.15
16
+ * allow auth option in MongoClient.connect
17
+ * remove duplicate option `promoteLongs` from MongoClient's `connect`
18
+ * bulk operations should not throw an error on empty batch
19
+
20
+ 2.2.30 2017-07-07
21
+ -----------------
22
+ * Update mongodb-core to 2.1.14
23
+ * MongoClient
24
+ * add `appname` to list of valid option names
25
+ * added test for passing appname as option
26
+ * NODE-1052 ensure user options are applied while parsing connection string uris
27
+
1
28
  2.2.29 2017-06-19
2
29
  -----------------
3
30
  * Update mongodb-core to 2.1.13
package/lib/admin.js CHANGED
@@ -248,7 +248,7 @@ Admin.prototype.authenticate = function(username, password, options, callback) {
248
248
  var finalArguments = [this.s.db];
249
249
  if(typeof username == 'string') finalArguments.push(username);
250
250
  if(typeof password == 'string') finalArguments.push(password);
251
- if(typeof options == 'function') {
251
+ if(typeof options == 'function') {
252
252
  finalArguments.push({ authdb: 'admin' });
253
253
  finalArguments.push(options);
254
254
  } else {
@@ -256,7 +256,7 @@ Admin.prototype.authenticate = function(username, password, options, callback) {
256
256
  }
257
257
 
258
258
  if(typeof callback == 'function') finalArguments.push(callback);
259
- // Excute authenticate method
259
+ // Execute authenticate method
260
260
  return authenticate.apply(this.s.db, finalArguments);
261
261
  }
262
262
 
@@ -435,7 +435,7 @@ var setProfilingLevel = function(self, level, callback) {
435
435
  define.classMethod('setProfilingLevel', {callback: true, promise:true});
436
436
 
437
437
  /**
438
- * Retrive the current profiling information for MongoDB
438
+ * Retrieve the current profiling information for MongoDB
439
439
  *
440
440
  * @param {Admin~resultCallback} [callback] The command result callback.
441
441
  * @return {Promise} returns Promise if no callback passed
@@ -144,7 +144,7 @@ var define = AggregationCursor.define = new Define('AggregationCursor', Aggregat
144
144
  */
145
145
  AggregationCursor.prototype.batchSize = function(value) {
146
146
  if(this.s.state == AggregationCursor.CLOSED || this.isDead()) throw MongoError.create({message: "Cursor is closed", driver:true });
147
- if(typeof value != 'number') throw MongoError.create({message: "batchSize requires an integer", drvier:true });
147
+ if(typeof value != 'number') throw MongoError.create({message: "batchSize requires an integer", driver:true });
148
148
  if(this.s.cmd.cursor) this.s.cmd.cursor.batchSize = value;
149
149
  this.setCursorBatchSize(value);
150
150
  return this;
@@ -350,7 +350,7 @@ define.classMethod('readBufferedDocuments', {callback: false, promise:false, ret
350
350
  /**
351
351
  * Returns an array of documents. The caller is responsible for making sure that there
352
352
  * is enough memory to store the results. Note that the array only contain partial
353
- * results when this cursor had been previouly accessed. In that case,
353
+ * results when this cursor had been previously accessed. In that case,
354
354
  * cursor.rewind() can be used to reset the cursor.
355
355
  * @method AggregationCursor.prototype.toArray
356
356
  * @param {AggregationCursor~toArrayResultCallback} [callback] The result callback.
@@ -367,7 +367,7 @@ define.classMethod('readBufferedDocuments', {callback: false, promise:false, ret
367
367
 
368
368
  /**
369
369
  * Iterates over all the documents for this cursor. As with **{cursor.toArray}**,
370
- * not all of the elements will be iterated if this cursor had been previouly accessed.
370
+ * not all of the elements will be iterated if this cursor had been previously accessed.
371
371
  * In that case, **{cursor.rewind}** can be used to reset the cursor. However, unlike
372
372
  * **{cursor.toArray}**, the cursor will only hold a maximum of batch size elements
373
373
  * at any given time if batch size is specified. Otherwise, the caller is responsible
package/lib/apm.js CHANGED
@@ -96,7 +96,7 @@ var Instrumentation = function(core, options, callback) {
96
96
  // The actual prototype
97
97
  proto[x] = function() {
98
98
  var requestId = core.Query.nextRequestId();
99
- // Get the aruments
99
+ // Get the arguments
100
100
  var args = Array.prototype.slice.call(arguments, 0);
101
101
  var ns = args[0];
102
102
  var commandObj = args[1];
@@ -261,7 +261,7 @@ var Instrumentation = function(core, options, callback) {
261
261
 
262
262
  // The actual prototype
263
263
  proto[x] = function() {
264
- // Get the aruments
264
+ // Get the arguments
265
265
  var args = Array.prototype.slice.call(arguments, 0);
266
266
  // Set an operation Id on the bulk object
267
267
  this.operationId = operationIdGenerator.next();
@@ -435,7 +435,7 @@ var Instrumentation = function(core, options, callback) {
435
435
  connectionId: connectionId
436
436
  };
437
437
 
438
- // Get the aruments
438
+ // Get the arguments
439
439
  var args = Array.prototype.slice.call(arguments, 0);
440
440
 
441
441
  // Get the callback
@@ -493,7 +493,7 @@ var Instrumentation = function(core, options, callback) {
493
493
  nextBatch: cursor.cursorState.documents
494
494
  }, ok:1
495
495
  }
496
- } else if((commandName.toLowerCase() == 'find'
496
+ } else if((commandName.toLowerCase() == 'find'
497
497
  || commandName.toLowerCase() == 'aggregate'
498
498
  || commandName.toLowerCase() == 'listcollections') && r == null) {
499
499
  r = {
@@ -7,7 +7,7 @@ var authenticate = function(self, username, password, options, callback) {
7
7
  if(self.serverConfig && self.serverConfig.isDestroyed()) return callback(new MongoError('topology was destroyed'));
8
8
 
9
9
  // the default db to authenticate against is 'self'
10
- // if authententicate is called from a retry context, it may be another one, like admin
10
+ // if authenticate is called from a retry context, it may be another one, like admin
11
11
  var authdb = options.dbName ? options.dbName : self.databaseName;
12
12
  authdb = self.authSource ? self.authSource : authdb;
13
13
  authdb = options.authdb ? options.authdb : authdb;
@@ -151,6 +151,7 @@ var BulkWriteResult = function(bulkResult) {
151
151
  /**
152
152
  * Returns a specific write error object
153
153
  *
154
+ * @param {number} index of the write error to return, returns null if there is no result for passed in index
154
155
  * @return {WriteError}
155
156
  */
156
157
  this.getWriteErrorAt = function(index) {
@@ -488,30 +488,37 @@ var executeCommands = function(self, callback) {
488
488
  */
489
489
  OrderedBulkOperation.prototype.execute = function(_writeConcern, callback) {
490
490
  var self = this;
491
- if(this.s.executed) throw new toError("batch cannot be re-executed");
492
- if(typeof _writeConcern == 'function') {
491
+ if (this.s.executed) {
492
+ var executedError = toError('batch cannot be re-executed');
493
+ return (typeof callback === 'function') ?
494
+ callback(executedError, null) : this.s.promiseLibrary.reject(executedError);
495
+ }
496
+
497
+ if (typeof _writeConcern === 'function') {
493
498
  callback = _writeConcern;
494
- } else if(_writeConcern && typeof _writeConcern == 'object') {
499
+ } else if (_writeConcern && typeof _writeConcern === 'object') {
495
500
  this.s.writeConcern = _writeConcern;
496
501
  }
497
502
 
498
503
  // If we have current batch
499
- if(this.s.currentBatch) this.s.batches.push(this.s.currentBatch)
504
+ if (this.s.currentBatch) this.s.batches.push(this.s.currentBatch)
500
505
 
501
506
  // If we have no operations in the bulk raise an error
502
- if(this.s.batches.length == 0) {
503
- throw toError("Invalid Operation, No operations in bulk");
507
+ if (this.s.batches.length == 0) {
508
+ var emptyBatchError = toError('Invalid Operation, no operations specified');
509
+ return (typeof callback === 'function') ?
510
+ callback(emptyBatchError, null) : this.s.promiseLibrary.reject(emptyBatchError);
504
511
  }
505
512
 
506
513
  // Execute using callback
507
- if(typeof callback == 'function') {
508
- return executeCommands(this, callback);
509
- }
514
+ if (typeof callback === 'function') {
515
+ return executeCommands(this, callback);
516
+ }
510
517
 
511
518
  // Return a Promise
512
519
  return new this.s.promiseLibrary(function(resolve, reject) {
513
520
  executeCommands(self, function(err, r) {
514
- if(err) return reject(err);
521
+ if (err) return reject(err);
515
522
  resolve(r);
516
523
  });
517
524
  });
@@ -213,7 +213,7 @@ var addToOperationsList = function(_self, docType, document) {
213
213
  var UnorderedBulkOperation = function(topology, collection, options) {
214
214
  options = options == null ? {} : options;
215
215
 
216
- // Get the namesspace for the write operations
216
+ // Get the namespace for the write operations
217
217
  var namespace = collection.collectionName;
218
218
  // Used to mark operation as executed
219
219
  var executed = false;
@@ -490,30 +490,37 @@ var executeBatches = function(self, callback) {
490
490
  */
491
491
  UnorderedBulkOperation.prototype.execute = function(_writeConcern, callback) {
492
492
  var self = this;
493
- if(this.s.executed) throw toError("batch cannot be re-executed");
494
- if(typeof _writeConcern == 'function') {
493
+ if (this.s.executed) {
494
+ var executedError = toError('batch cannot be re-executed');
495
+ return (typeof callback === 'function') ?
496
+ callback(executedError, null) : this.s.promiseLibrary.reject(executedError);
497
+ }
498
+
499
+ if (typeof _writeConcern === 'function') {
495
500
  callback = _writeConcern;
496
- } else if(_writeConcern && typeof _writeConcern == 'object') {
501
+ } else if (_writeConcern && typeof _writeConcern === 'object') {
497
502
  this.s.writeConcern = _writeConcern;
498
503
  }
499
504
 
500
505
  // If we have current batch
501
- if(this.s.currentInsertBatch) this.s.batches.push(this.s.currentInsertBatch);
502
- if(this.s.currentUpdateBatch) this.s.batches.push(this.s.currentUpdateBatch);
503
- if(this.s.currentRemoveBatch) this.s.batches.push(this.s.currentRemoveBatch);
506
+ if (this.s.currentInsertBatch) this.s.batches.push(this.s.currentInsertBatch);
507
+ if (this.s.currentUpdateBatch) this.s.batches.push(this.s.currentUpdateBatch);
508
+ if (this.s.currentRemoveBatch) this.s.batches.push(this.s.currentRemoveBatch);
504
509
 
505
510
  // If we have no operations in the bulk raise an error
506
- if(this.s.batches.length == 0) {
507
- throw toError("Invalid Operation, No operations in bulk");
511
+ if (this.s.batches.length == 0) {
512
+ var emptyBatchError = toError('Invalid Operation, no operations specified');
513
+ return (typeof callback === 'function') ?
514
+ callback(emptyBatchError, null) : this.s.promiseLibrary.reject(emptyBatchError);
508
515
  }
509
516
 
510
517
  // Execute using callback
511
- if(typeof callback == 'function') return executeBatches(this, callback);
518
+ if (typeof callback === 'function') return executeBatches(this, callback);
512
519
 
513
520
  // Return a Promise
514
521
  return new this.s.promiseLibrary(function(resolve, reject) {
515
522
  executeBatches(self, function(err, r) {
516
- if(err) return reject(err);
523
+ if (err) return reject(err);
517
524
  resolve(r);
518
525
  });
519
526
  });
package/lib/collection.js CHANGED
@@ -21,8 +21,7 @@ var checkCollectionName = require('./utils').checkCollectionName
21
21
  , Cursor = require('./cursor')
22
22
  , unordered = require('./bulk/unordered')
23
23
  , ordered = require('./bulk/ordered')
24
- , assign = require('./utils').assign
25
- , mergeOptions = require('./utils').mergeOptions;
24
+ , assign = require('./utils').assign;
26
25
 
27
26
  /**
28
27
  * @fileOverview The **Collection** class is an internal class that embodies a MongoDB collection
@@ -417,7 +416,7 @@ Collection.prototype.insertOne = function(doc, options, callback) {
417
416
  });
418
417
  }
419
418
 
420
- // Add ignoreUndfined
419
+ // Add ignoreUndefined
421
420
  if(this.s.options.ignoreUndefined) {
422
421
  options = shallowClone(options);
423
422
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -448,7 +447,7 @@ var insertOne = function(self, doc, options, callback) {
448
447
  });
449
448
  }
450
449
 
451
- var mapInserManyResults = function(docs, r) {
450
+ var mapInsertManyResults = function(docs, r) {
452
451
  var ids = r.getInsertedIds();
453
452
  var keys = Object.keys(ids);
454
453
  var finalIds = new Array(keys.length);
@@ -533,14 +532,14 @@ Collection.prototype.insertMany = function(docs, options, callback) {
533
532
  // Execute using callback
534
533
  if(typeof callback == 'function') return bulkWrite(self, operations, options, function(err, r) {
535
534
  if(err) return callback(err, r);
536
- callback(null, mapInserManyResults(docs, r));
535
+ callback(null, mapInsertManyResults(docs, r));
537
536
  });
538
537
 
539
538
  // Return a Promise
540
539
  return new this.s.promiseLibrary(function(resolve, reject) {
541
540
  bulkWrite(self, operations, options, function(err, r) {
542
541
  if(err) return reject(err);
543
- resolve(mapInserManyResults(docs, r));
542
+ resolve(mapInsertManyResults(docs, r));
544
543
  });
545
544
  });
546
545
  }
@@ -621,7 +620,7 @@ Collection.prototype.bulkWrite = function(operations, options, callback) {
621
620
  }
622
621
 
623
622
  var bulkWrite = function(self, operations, options, callback) {
624
- // Add ignoreUndfined
623
+ // Add ignoreUndefined
625
624
  if(self.s.options.ignoreUndefined) {
626
625
  options = shallowClone(options);
627
626
  options.ignoreUndefined = self.s.options.ignoreUndefined;
@@ -878,7 +877,7 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
878
877
  if(typeof options == 'function') callback = options, options = {};
879
878
  options = shallowClone(options)
880
879
 
881
- // Add ignoreUndfined
880
+ // Add ignoreUndefined
882
881
  if(this.s.options.ignoreUndefined) {
883
882
  options = shallowClone(options);
884
883
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -933,7 +932,7 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
933
932
  if(typeof options == 'function') callback = options, options = {};
934
933
  options = shallowClone(options)
935
934
 
936
- // Add ignoreUndfined
935
+ // Add ignoreUndefined
937
936
  if(this.s.options.ignoreUndefined) {
938
937
  options = shallowClone(options);
939
938
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -990,7 +989,7 @@ Collection.prototype.updateMany = function(filter, update, options, callback) {
990
989
  if(typeof options == 'function') callback = options, options = {};
991
990
  options = shallowClone(options)
992
991
 
993
- // Add ignoreUndfined
992
+ // Add ignoreUndefined
994
993
  if(this.s.options.ignoreUndefined) {
995
994
  options = shallowClone(options);
996
995
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -1084,7 +1083,7 @@ var updateDocuments = function(self, selector, document, options, callback) {
1084
1083
  Collection.prototype.update = function(selector, document, options, callback) {
1085
1084
  var self = this;
1086
1085
 
1087
- // Add ignoreUndfined
1086
+ // Add ignoreUndefined
1088
1087
  if(this.s.options.ignoreUndefined) {
1089
1088
  options = shallowClone(options);
1090
1089
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -1136,7 +1135,7 @@ Collection.prototype.deleteOne = function(filter, options, callback) {
1136
1135
  if(typeof options == 'function') callback = options, options = {};
1137
1136
  options = shallowClone(options);
1138
1137
 
1139
- // Add ignoreUndfined
1138
+ // Add ignoreUndefined
1140
1139
  if(this.s.options.ignoreUndefined) {
1141
1140
  options = shallowClone(options);
1142
1141
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -1187,7 +1186,7 @@ Collection.prototype.deleteMany = function(filter, options, callback) {
1187
1186
  if(typeof options == 'function') callback = options, options = {};
1188
1187
  options = shallowClone(options);
1189
1188
 
1190
- // Add ignoreUndfined
1189
+ // Add ignoreUndefined
1191
1190
  if(this.s.options.ignoreUndefined) {
1192
1191
  options = shallowClone(options);
1193
1192
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -1276,7 +1275,7 @@ define.classMethod('removeMany', {callback: true, promise:true});
1276
1275
  Collection.prototype.remove = function(selector, options, callback) {
1277
1276
  var self = this;
1278
1277
 
1279
- // Add ignoreUndfined
1278
+ // Add ignoreUndefined
1280
1279
  if(this.s.options.ignoreUndefined) {
1281
1280
  options = shallowClone(options);
1282
1281
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -1314,7 +1313,7 @@ Collection.prototype.save = function(doc, options, callback) {
1314
1313
  if(typeof options == 'function') callback = options, options = {};
1315
1314
  options = options || {};
1316
1315
 
1317
- // Add ignoreUndfined
1316
+ // Add ignoreUndefined
1318
1317
  if(this.s.options.ignoreUndefined) {
1319
1318
  options = shallowClone(options);
1320
1319
  options.ignoreUndefined = this.s.options.ignoreUndefined;
@@ -1386,7 +1385,7 @@ define.classMethod('save', {callback: true, promise:true});
1386
1385
  * @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
1387
1386
  * @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
1388
1387
  * @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
1389
- * @param {number} [options.maxTimeMS=null] Number of miliseconds to wait before aborting the query.
1388
+ * @param {number} [options.maxTimeMS=null] Number of milliseconds to wait before aborting the query.
1390
1389
  * @param {object} [options.collation=null] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
1391
1390
  * @param {Collection~resultCallback} [callback] The command result callback
1392
1391
  * @return {Promise} returns Promise if no callback passed
@@ -1997,7 +1996,7 @@ define.classMethod('indexInformation', {callback: true, promise:true});
1997
1996
  * @param {boolean} [options.skip=null] The number of documents to skip for the count.
1998
1997
  * @param {string} [options.hint=null] An index name hint for the query.
1999
1998
  * @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
2000
- * @param {number} [options.maxTimeMS=null] Number of miliseconds to wait before aborting the query.
1999
+ * @param {number} [options.maxTimeMS=null] Number of milliseconds to wait before aborting the query.
2001
2000
  * @param {Collection~countCallback} [callback] The command result callback
2002
2001
  * @return {Promise} returns Promise if no callback passed
2003
2002
  */
@@ -2070,7 +2069,7 @@ define.classMethod('count', {callback: true, promise:true});
2070
2069
  * @param {object} query The query for filtering the set of documents to which we apply the distinct filter.
2071
2070
  * @param {object} [options=null] Optional settings.
2072
2071
  * @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
2073
- * @param {number} [options.maxTimeMS=null] Number of miliseconds to wait before aborting the query.
2072
+ * @param {number} [options.maxTimeMS=null] Number of milliseconds to wait before aborting the query.
2074
2073
  * @param {Collection~resultCallback} [callback] The command result callback
2075
2074
  * @return {Promise} returns Promise if no callback passed
2076
2075
  */
@@ -2656,13 +2655,18 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
2656
2655
  options = getReadPreference(this, options, this.s.db, this);
2657
2656
 
2658
2657
  // If explain has been specified add it
2659
- if(options.explain) command.explain = options.explain;
2658
+ if (options.explain) command.explain = options.explain;
2660
2659
 
2661
2660
  // Validate that cursor options is valid
2662
2661
  if(options.cursor != null && typeof options.cursor != 'object') {
2663
2662
  throw toError('cursor options must be an object');
2664
2663
  }
2665
2664
 
2665
+ if (this.s.topology.capabilities().hasAggregationCursor) {
2666
+ options.cursor = options.cursor || { batchSize : 1000 };
2667
+ command.cursor = options.cursor;
2668
+ }
2669
+
2666
2670
  // promiseLibrary
2667
2671
  options.promiseLibrary = this.s.promiseLibrary;
2668
2672
 
@@ -2673,11 +2677,6 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
2673
2677
  throw new MongoError('cannot connect to server');
2674
2678
  }
2675
2679
 
2676
- if(this.s.topology.capabilities().hasAggregationCursor) {
2677
- options.cursor = options.cursor || { batchSize : 1000 };
2678
- command.cursor = options.cursor;
2679
- }
2680
-
2681
2680
  // Allow disk usage command
2682
2681
  if(typeof options.allowDiskUse == 'boolean') command.allowDiskUse = options.allowDiskUse;
2683
2682
  if(typeof options.maxTimeMS == 'number') command.maxTimeMS = options.maxTimeMS;
@@ -2686,12 +2685,18 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
2686
2685
  return this.s.topology.cursor(this.s.namespace, command, options);
2687
2686
  }
2688
2687
 
2689
- // We do not allow cursor
2690
- if(options.cursor) {
2691
- return this.s.topology.cursor(this.s.namespace, command, options);
2688
+ if (options.cursor) {
2689
+ var cursor = this.s.topology.cursor(this.s.namespace, command, options);
2690
+ return cursor.toArray(function(err, result) {
2691
+ if (err) {
2692
+ return handleCallback(callback, err);
2693
+ }
2694
+
2695
+ handleCallback(callback, null, result);
2696
+ });
2692
2697
  }
2693
2698
 
2694
- // Execute the command
2699
+ // For legacy server versions, we execute the command and format the result
2695
2700
  this.s.db.command(command, options, function(err, result) {
2696
2701
  if(err) {
2697
2702
  handleCallback(callback, err);
@@ -3366,6 +3371,7 @@ var testForFields = {
3366
3371
  , numberOfRetries: 1, awaitdata: 1, awaitData: 1, exhaust: 1, batchSize: 1, returnKey: 1, maxScan: 1, min: 1, max: 1, showDiskLoc: 1
3367
3372
  , comment: 1, raw: 1, readPreference: 1, partial: 1, read: 1, dbName: 1, oplogReplay: 1, connection: 1, maxTimeMS: 1, transforms: 1
3368
3373
  , collation: 1
3374
+ , noCursorTimeout: 1
3369
3375
  }
3370
3376
 
3371
3377
  module.exports = Collection;
@@ -240,7 +240,7 @@ define.classMethod('readBufferedDocuments', {callback: false, promise:false, ret
240
240
  /**
241
241
  * Returns an array of documents. The caller is responsible for making sure that there
242
242
  * is enough memory to store the results. Note that the array only contain partial
243
- * results when this cursor had been previouly accessed.
243
+ * results when this cursor had been previously accessed.
244
244
  * @method CommandCursor.prototype.toArray
245
245
  * @param {CommandCursor~toArrayResultCallback} [callback] The result callback.
246
246
  * @throws {MongoError}
@@ -256,7 +256,7 @@ define.classMethod('readBufferedDocuments', {callback: false, promise:false, ret
256
256
 
257
257
  /**
258
258
  * Iterates over all the documents for this cursor. As with **{cursor.toArray}**,
259
- * not all of the elements will be iterated if this cursor had been previouly accessed.
259
+ * not all of the elements will be iterated if this cursor had been previously accessed.
260
260
  * In that case, **{cursor.rewind}** can be used to reset the cursor. However, unlike
261
261
  * **{cursor.toArray}**, the cursor will only hold a maximum of batch size elements
262
262
  * at any given time if batch size is specified. Otherwise, the caller is responsible
package/lib/cursor.js CHANGED
@@ -221,7 +221,8 @@ Cursor.prototype.hasNext = function(callback) {
221
221
  return callback(null, true);
222
222
  } else {
223
223
  return nextObject(self, function(err, doc) {
224
- if(!doc) return callback(null, false);
224
+ if (err) return callback(err, null);
225
+ if (!doc) return callback(null, false);
225
226
  self.s.currentDoc = doc;
226
227
  callback(null, true);
227
228
  });
@@ -702,7 +703,7 @@ define.classMethod('next', {callback: true, promise:true});
702
703
 
703
704
  /**
704
705
  * Iterates over all the documents for this cursor. As with **{cursor.toArray}**,
705
- * not all of the elements will be iterated if this cursor had been previouly accessed.
706
+ * not all of the elements will be iterated if this cursor had been previously accessed.
706
707
  * In that case, **{cursor.rewind}** can be used to reset the cursor. However, unlike
707
708
  * **{cursor.toArray}**, the cursor will only hold a maximum of batch size elements
708
709
  * at any given time if batch size is specified. Otherwise, the caller is responsible
@@ -821,7 +822,7 @@ define.classMethod('setReadPreference', {callback: false, promise:false, returns
821
822
  /**
822
823
  * Returns an array of documents. The caller is responsible for making sure that there
823
824
  * is enough memory to store the results. Note that the array only contain partial
824
- * results when this cursor had been previouly accessed. In that case,
825
+ * results when this cursor had been previously accessed. In that case,
825
826
  * cursor.rewind() can be used to reset the cursor.
826
827
  * @method
827
828
  * @param {Cursor~toArrayResultCallback} [callback] The result callback.
@@ -899,7 +900,7 @@ define.classMethod('toArray', {callback: true, promise:true});
899
900
  * @param {object} [options=null] Optional settings.
900
901
  * @param {number} [options.skip=null] The number of documents to skip.
901
902
  * @param {number} [options.limit=null] The maximum amounts to count before aborting.
902
- * @param {number} [options.maxTimeMS=null] Number of miliseconds to wait before aborting the query.
903
+ * @param {number} [options.maxTimeMS=null] Number of milliseconds to wait before aborting the query.
903
904
  * @param {string} [options.hint=null] An index name hint for the query.
904
905
  * @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
905
906
  * @param {Cursor~countResultCallback} [callback] The result callback.
package/lib/db.js CHANGED
@@ -173,6 +173,7 @@ var Db = function(databaseName, topology, options) {
173
173
  topology.once('fullsetup', createListener(self, 'fullsetup', self));
174
174
  topology.once('all', createListener(self, 'all', self));
175
175
  topology.on('reconnect', createListener(self, 'reconnect', self));
176
+ topology.on('reconnectFailed', createListener(self, 'reconnectFailed', self));
176
177
  }
177
178
 
178
179
  inherits(Db, EventEmitter);
@@ -767,7 +768,7 @@ var evaluate = function(self, code, parameters, options, callback) {
767
768
  * @param {Code} code JavaScript to execute on server.
768
769
  * @param {(object|array)} parameters The parameters for the call.
769
770
  * @param {object} [options=null] Optional settings.
770
- * @param {boolean} [options.nolock=false] Tell MongoDB not to block on the evaulation of the javascript.
771
+ * @param {boolean} [options.nolock=false] Tell MongoDB not to block on the evaluation of the javascript.
771
772
  * @param {Db~resultCallback} [callback] The results callback
772
773
  * @deprecated Eval is deprecated on MongoDB 3.2 and forward
773
774
  * @return {Promise} returns Promise if no callback passed
@@ -1150,7 +1151,7 @@ var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
1150
1151
  // Merge primary readPreference
1151
1152
  finalOptions.readPreference = ReadPreference.PRIMARY
1152
1153
 
1153
- // Check if the index allready exists
1154
+ // Check if the index already exists
1154
1155
  self.indexInformation(name, finalOptions, function(err, indexInformation) {
1155
1156
  if(err != null && err.code != 26) return handleCallback(callback, err, null);
1156
1157
  // If the index does not exist, create it
@@ -61,7 +61,7 @@ var REFERENCE_BY_FILENAME = 0,
61
61
  *
62
62
  * Modes
63
63
  * - **"r"** - read only. This is the default mode.
64
- * - **"w"** - write in truncate mode. Existing data will be overwriten.
64
+ * - **"w"** - write in truncate mode. Existing data will be overwritten.
65
65
  *
66
66
  * @class
67
67
  * @param {Db} db A database instance to interact with.
@@ -35,10 +35,10 @@ var validOptionNames = ['poolSize', 'ssl', 'sslValidate', 'sslCA', 'sslCert',
35
35
  'socketTimeoutMS', 'reconnectTries', 'reconnectInterval', 'ha', 'haInterval',
36
36
  'replicaSet', 'secondaryAcceptableLatencyMS', 'acceptableLatencyMS',
37
37
  'connectWithNoPrimary', 'authSource', 'w', 'wtimeout', 'j', 'forceServerObjectId',
38
- 'serializeFunctions', 'ignoreUndefined', 'raw', 'promoteLongs', 'bufferMaxEntries',
38
+ 'serializeFunctions', 'ignoreUndefined', 'raw', 'bufferMaxEntries',
39
39
  'readPreference', 'pkFactory', 'promiseLibrary', 'readConcern', 'maxStalenessSeconds',
40
40
  'loggerLevel', 'logger', 'promoteValues', 'promoteBuffers', 'promoteLongs',
41
- 'domainsEnabled', 'keepAliveInitialDelay', 'checkServerIdentity', 'validateOptions'];
41
+ 'domainsEnabled', 'keepAliveInitialDelay', 'checkServerIdentity', 'validateOptions', 'appname', 'auth'];
42
42
  var ignoreOptionNames = ['native_parser'];
43
43
  var legacyOptionNames = ['server', 'replset', 'replSet', 'mongos', 'db'];
44
44
 
@@ -114,6 +114,8 @@ function MongoClient() {
114
114
  * @param {number} [options.acceptableLatencyMS=15] Cutoff latency point in MS for Mongos proxies selection.
115
115
  * @param {boolean} [options.connectWithNoPrimary=false] Sets if the driver should connect even if no primary is available
116
116
  * @param {string} [options.authSource=undefined] Define the database to authenticate against
117
+ * @param {string} [options.auth.user=undefined] The username for auth
118
+ * @param {string} [options.auth.password=undefined] The password for auth
117
119
  * @param {(number|string)} [options.w=null] The write concern.
118
120
  * @param {number} [options.wtimeout=null] The write concern timeout.
119
121
  * @param {boolean} [options.j=false] Specify a journal write concern.
@@ -132,6 +134,7 @@ function MongoClient() {
132
134
  * @param {object} [options.readConcern=null] Specify a read concern for the collection. (only MongoDB 3.2 or higher supported)
133
135
  * @param {string} [options.readConcern.level='local'] Specify a read concern level for the collection operations, one of [local|majority]. (only MongoDB 3.2 or higher supported)
134
136
  * @param {number} [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed);
137
+ * @param {string} [options.appname=undefined] The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections.
135
138
  * @param {string} [options.loggerLevel=undefined] The logging level (error/warn/info/debug)
136
139
  * @param {object} [options.logger=undefined] Custom logger object
137
140
  * @param {object} [options.validateOptions=false] Validate MongoClient passed in options for correctness.
@@ -182,6 +185,8 @@ var define = MongoClient.define = new Define('MongoClient', MongoClient, false);
182
185
  * @param {number} [options.acceptableLatencyMS=15] Cutoff latency point in MS for Mongos proxies selection.
183
186
  * @param {boolean} [options.connectWithNoPrimary=false] Sets if the driver should connect even if no primary is available
184
187
  * @param {string} [options.authSource=undefined] Define the database to authenticate against
188
+ * @param {string} [options.auth.user=undefined] The username for auth
189
+ * @param {string} [options.auth.password=undefined] The password for auth
185
190
  * @param {(number|string)} [options.w=null] The write concern.
186
191
  * @param {number} [options.wtimeout=null] The write concern timeout.
187
192
  * @param {boolean} [options.j=false] Specify a journal write concern.
@@ -200,6 +205,7 @@ var define = MongoClient.define = new Define('MongoClient', MongoClient, false);
200
205
  * @param {object} [options.readConcern=null] Specify a read concern for the collection. (only MongoDB 3.2 or higher supported)
201
206
  * @param {string} [options.readConcern.level='local'] Specify a read concern level for the collection operations, one of [local|majority]. (only MongoDB 3.2 or higher supported)
202
207
  * @param {number} [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed);
208
+ * @param {string} [options.appname=undefined] The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections.
203
209
  * @param {string} [options.loggerLevel=undefined] The logging level (error/warn/info/debug)
204
210
  * @param {object} [options.logger=undefined] Custom logger object
205
211
  * @param {object} [options.validateOptions=false] Validate MongoClient passed in options for correctness.
@@ -486,6 +492,10 @@ var connect = function(self, url, options, callback) {
486
492
  if(_finalOptions.socketTimeoutMS == null) _finalOptions.socketTimeoutMS = 360000;
487
493
  if(_finalOptions.connectTimeoutMS == null) _finalOptions.connectTimeoutMS = 30000;
488
494
 
495
+ if (_finalOptions.db_options && _finalOptions.db_options.auth) {
496
+ delete _finalOptions.db_options.auth;
497
+ }
498
+
489
499
  // Failure modes
490
500
  if(object.servers.length == 0) {
491
501
  throw new Error("connection string must contain at least one seed host");
@@ -39,7 +39,7 @@
39
39
  * @param {string} mode The ReadPreference mode as listed above.
40
40
  * @param {array|object} tags An object representing read preference tags.
41
41
  * @param {object} [options] Additional read preference options
42
- * @param {number} [options.maxStalenessSeconds] Max Secondary Read Stalleness in Seconds
42
+ * @param {number} [options.maxStalenessSeconds] Max Secondary Read Staleness in Seconds
43
43
  * @return {ReadPreference} a ReadPreference instance.
44
44
  */
45
45
  var ReadPreference = function(mode, tags, options) {
package/lib/server.js CHANGED
@@ -70,8 +70,8 @@ var release = os.release();
70
70
  * @param {(Buffer|string)} [options.sslKey=null] String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher)
71
71
  * @param {(Buffer|string)} [options.sslPass=null] String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher)
72
72
  * @param {string} [options.servername=null] String containing the server name requested via TLS SNI.
73
+ * @param {boolean} [options.autoReconnect=true] Reconnect on error or timeout.
73
74
  * @param {object} [options.socketOptions=null] Socket options
74
- * @param {boolean} [options.socketOptions.autoReconnect=true] Reconnect on error.
75
75
  * @param {boolean} [options.socketOptions.noDelay=true] TCP Socket NoDelay option.
76
76
  * @param {number} [options.socketOptions.keepAlive=0] TCP KeepAlive on the socket with a X ms delay before start.
77
77
  * @param {number} [options.socketOptions.connectTimeoutMS=0] TCP Connection timeout setting