mongodb 2.2.31 → 2.2.35

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,13 +1,59 @@
1
+ <a name="2.2.35"></a>
2
+ ## [2.2.35](https://github.com/mongodb/node-mongodb-native/compare/v2.2.34...v2.2.35) (2018-02-26)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * **url parser:** preserve auth creds when composing conn string ([#1641](https://github.com/mongodb/node-mongodb-native/issues/1641)) ([ecedce6](https://github.com/mongodb/node-mongodb-native/commit/ecedce6))
8
+
9
+
10
+ ### Features
11
+
12
+ * **core**: update mongodb-core to 2.1.19
13
+
14
+
15
+
16
+ <a name="2.2.34"></a>
17
+ ## [2.2.34](https://github.com/mongodb/node-mongodb-native/compare/v2.2.33...v2.2.34) (2018-01-03)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **collection:** allow { upsert: 1 } for findOneAndUpdate() and update() ([#1580](https://github.com/mongodb/node-mongodb-native/issues/1580)) ([0f338c8](https://github.com/mongodb/node-mongodb-native/commit/0f338c8)), closes [Automattic/mongoose#5839](https://github.com/Automattic/mongoose/issues/5839)
23
+ * **GridFS:** fix TypeError: doc.data.length is not a function ([811de0c](https://github.com/mongodb/node-mongodb-native/commit/811de0c))
24
+ * **import:** adds missing import to lib/authenticate.js ([10db9a2](https://github.com/mongodb/node-mongodb-native/commit/10db9a2))
25
+ * **list-collections:** ensure default of primary ReadPreference ([0935306](https://github.com/mongodb/node-mongodb-native/commit/0935306))
26
+
27
+
28
+ ### Features
29
+
30
+ * **ssl:** adds missing ssl options ssl options for `ciphers` and `ecdhCurve` ([bd4fb53](https://github.com/mongodb/node-mongodb-native/commit/bd4fb53))
31
+ * **url parser:** add dns seedlist support ([2d357bc](https://github.com/mongodb/node-mongodb-native/commit/2d357bc))
32
+ * **core**: update mongodb-core to 2.1.18
33
+
34
+
35
+ 2.2.33 2017-10-12
36
+ -----------------
37
+ * update to mongodb-core 2.1.17
38
+
39
+ 2.2.32 2017-10-11
40
+ -----------------
41
+ * update to mongodb-core 2.1.16
42
+ * ensure that the `cursor` key is always present in aggregation commands
43
+ * `Cursor.prototype.hasNext` now propagates errors when using callback
44
+ * allow passing `noCursorTimeout` as an option to `find()`
45
+ * bubble up `reconnectFailed` event from Server topology
46
+
1
47
  2.2.31 2017-08-08
2
48
  -----------------
3
- * update mongodb-core to 2.2.15
49
+ * update mongodb-core to 2.1.15
4
50
  * allow auth option in MongoClient.connect
5
51
  * remove duplicate option `promoteLongs` from MongoClient's `connect`
6
52
  * bulk operations should not throw an error on empty batch
7
53
 
8
54
  2.2.30 2017-07-07
9
55
  -----------------
10
- * Update mongodb-core to 2.2.14
56
+ * Update mongodb-core to 2.1.14
11
57
  * MongoClient
12
58
  * add `appname` to list of valid option names
13
59
  * added test for passing appname as option
package/README.md CHANGED
@@ -325,7 +325,7 @@ Next lets delete the document where the field **a** equals to **3**.
325
325
  var deleteDocument = function(db, callback) {
326
326
  // Get the documents collection
327
327
  var collection = db.collection('documents');
328
- // Insert some documents
328
+ // Delete document where a is 3
329
329
  collection.deleteOne({ a : 3 }, function(err, result) {
330
330
  assert.equal(err, null);
331
331
  assert.equal(1, result.result.n);
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 = {
@@ -1,13 +1,14 @@
1
1
  var shallowClone = require('./utils').shallowClone
2
2
  , handleCallback = require('./utils').handleCallback
3
- , MongoError = require('mongodb-core').MongoError;
3
+ , MongoError = require('mongodb-core').MongoError
4
+ , f = require('util').format;
4
5
 
5
6
  var authenticate = function(self, username, password, options, callback) {
6
7
  // Did the user destroy the topology
7
8
  if(self.serverConfig && self.serverConfig.isDestroyed()) return callback(new MongoError('topology was destroyed'));
8
9
 
9
10
  // the default db to authenticate against is 'self'
10
- // if authententicate is called from a retry context, it may be another one, like admin
11
+ // if authenticate is called from a retry context, it may be another one, like admin
11
12
  var authdb = options.dbName ? options.dbName : self.databaseName;
12
13
  authdb = self.authSource ? self.authSource : authdb;
13
14
  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) {
@@ -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;
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;
@@ -1045,8 +1044,8 @@ var updateDocuments = function(self, selector, document, options, callback) {
1045
1044
 
1046
1045
  // Execute the operation
1047
1046
  var op = {q: selector, u: document};
1048
- op.upsert = typeof options.upsert == 'boolean' ? options.upsert : false;
1049
- op.multi = typeof options.multi == 'boolean' ? options.multi : false;
1047
+ op.upsert = options.upsert !== void 0 ? !!options.upsert : false;
1048
+ op.multi = options.multi !== void 0 ? !!options.multi : false;
1050
1049
 
1051
1050
  // Have we specified collation
1052
1051
  decorateWithCollation(finalOptions, self, options);
@@ -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
  */
@@ -2372,8 +2371,8 @@ var findOneAndUpdate = function(self, filter, update, options, callback) {
2372
2371
  var finalOptions = shallowClone(options);
2373
2372
  finalOptions['fields'] = options.projection;
2374
2373
  finalOptions['update'] = true;
2375
- finalOptions['new'] = typeof options.returnOriginal == 'boolean' ? !options.returnOriginal : false;
2376
- finalOptions['upsert'] = typeof options.upsert == 'boolean' ? options.upsert : false;
2374
+ finalOptions['new'] = options.returnOriginal !== void 0 ? !options.returnOriginal : false;
2375
+ finalOptions['upsert'] = options.upsert !== void 0 ? !!options.upsert : false;
2377
2376
 
2378
2377
  // Execute findAndModify
2379
2378
  self.findAndModify(
@@ -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);
@@ -652,7 +653,7 @@ var listCollectionsTranforms = function(databaseName) {
652
653
  * Get the list of all collection information for the specified db.
653
654
  *
654
655
  * @method
655
- * @param {object} filter Query to filter collections by
656
+ * @param {object} [filter={}] Query to filter collections by
656
657
  * @param {object} [options=null] Optional settings.
657
658
  * @param {number} [options.batchSize=null] The batchSize for the returned command cursor or if pre 2.8 the systems batch collection
658
659
  * @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
@@ -670,6 +671,8 @@ Db.prototype.listCollections = function(filter, options) {
670
671
  // Ensure valid readPreference
671
672
  if(options.readPreference) {
672
673
  options.readPreference = convertReadPreference(options.readPreference);
674
+ } else {
675
+ options.readPreference = this.s.readPreference || CoreReadPreference.primary;
673
676
  }
674
677
 
675
678
  // We have a list collections command
@@ -767,7 +770,7 @@ var evaluate = function(self, code, parameters, options, callback) {
767
770
  * @param {Code} code JavaScript to execute on server.
768
771
  * @param {(object|array)} parameters The parameters for the call.
769
772
  * @param {object} [options=null] Optional settings.
770
- * @param {boolean} [options.nolock=false] Tell MongoDB not to block on the evaulation of the javascript.
773
+ * @param {boolean} [options.nolock=false] Tell MongoDB not to block on the evaluation of the javascript.
771
774
  * @param {Db~resultCallback} [callback] The results callback
772
775
  * @deprecated Eval is deprecated on MongoDB 3.2 and forward
773
776
  * @return {Promise} returns Promise if no callback passed
@@ -1150,7 +1153,7 @@ var ensureIndex = function(self, name, fieldOrSpec, options, callback) {
1150
1153
  // Merge primary readPreference
1151
1154
  finalOptions.readPreference = ReadPreference.PRIMARY
1152
1155
 
1153
- // Check if the index allready exists
1156
+ // Check if the index already exists
1154
1157
  self.indexInformation(name, finalOptions, function(err, indexInformation) {
1155
1158
  if(err != null && err.code != 26) return handleCallback(callback, err, null);
1156
1159
  // 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.
@@ -209,26 +209,27 @@ function doRead(_this) {
209
209
  return __handleError(_this, new Error(errmsg));
210
210
  }
211
211
 
212
- if (doc.data.length() !== expectedLength) {
212
+ var buf = Buffer.isBuffer(doc.data) ? doc.data : doc.data.buffer;
213
+
214
+ if (buf.length !== expectedLength) {
213
215
  if (bytesRemaining <= 0) {
214
216
  errmsg = 'ExtraChunk: Got unexpected n: ' + doc.n;
215
217
  return __handleError(_this, new Error(errmsg));
216
218
  }
217
219
 
218
220
  errmsg = 'ChunkIsWrongSize: Got unexpected length: ' +
219
- doc.data.length() + ', expected: ' + expectedLength;
221
+ buf.length + ', expected: ' + expectedLength;
220
222
  return __handleError(_this, new Error(errmsg));
221
223
  }
222
224
 
223
- _this.s.bytesRead += doc.data.length();
225
+ _this.s.bytesRead += buf.length;
224
226
 
225
- if (doc.data.buffer.length === 0) {
227
+ if (buf.length === 0) {
226
228
  return _this.push(null);
227
229
  }
228
230
 
229
231
  var sliceStart = null;
230
232
  var sliceEnd = null;
231
- var buf = doc.data.buffer;
232
233
 
233
234
  if (_this.s.bytesToSkip != null) {
234
235
  sliceStart = _this.s.bytesToSkip;
@@ -241,7 +242,7 @@ function doRead(_this) {
241
242
 
242
243
  // If the remaining amount of data left is < chunkSize read the right amount of data
243
244
  if (_this.s.options.end && (
244
- (_this.s.options.end - _this.s.bytesToSkip) < doc.data.length()
245
+ (_this.s.options.end - _this.s.bytesToSkip) < buf.length
245
246
  )) {
246
247
  sliceEnd = (_this.s.options.end - _this.s.bytesToSkip);
247
248
  }