Skip to content

Commit cf1cdea

Browse files
committed
Merged back 2.0 branch
2 parents 7b9ae64 + 23dd36f commit cf1cdea

File tree

11 files changed

+193
-25
lines changed

11 files changed

+193
-25
lines changed

HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2.0.43
2+
-----------------
3+
* Propegate timeout event correctly to db instances
4+
5+
2.0.42 08-18-2015
6+
-----------------
7+
* Added test case to exercise all non-crud methods on mongos topologies, fixed numberOfConnectedServers on mongos topology instance.
8+
19
2.0.41 08-14-2015
210
-----------------
311
* Added missing Mongos.prototype.parserType function.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ http://jira.mongodb.org/browse/NODE
4343

4444
QuickStart
4545
==========
46-
The quick start guide will show you how to setup a simple application using node.js and MongoDB. It scope is only how to set up the driver and perform the simple crud operations. For more in depth coverage we encourage reading the tutorials.
46+
The quick start guide will show you how to setup a simple application using node.js and MongoDB. Its scope is only how to set up the driver and perform the simple crud operations. For more in depth coverage we encourage reading the tutorials.
4747

4848
Create the package.json file
4949
----------------------------

conf.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib/bulk/ordered.js",
2222
"lib/bulk/unordered.js",
2323
"lib/gridfs/grid_store.js",
24+
"node_modules/mongodb-core/lib/error.js",
2425
"node_modules/mongodb-core/lib/connection/logger.js",
2526
"node_modules/bson/lib/bson/binary.js",
2627
"node_modules/bson/lib/bson/code.js",

lib/collection.js

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ define.classMethod('find', {callback: false, promise:false, returns: [Cursor]});
355355
* @param {boolean} [options.j=false] Specify a journal write concern.
356356
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
357357
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
358-
* @param {Collection~writeOpCallback} [callback] The command result callback
358+
* @param {Collection~insertWriteOpCallback} [callback] The command result callback
359359
* @return {Promise} returns Promise if no callback passed
360360
*/
361361
Collection.prototype.insertOne = function(doc, options, callback) {
@@ -420,7 +420,7 @@ define.classMethod('insertOne', {callback: true, promise:true});
420420
* @param {boolean} [options.j=false] Specify a journal write concern.
421421
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
422422
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
423-
* @param {Collection~writeOpCallback} [callback] The command result callback
423+
* @param {Collection~insertWriteOpCallback} [callback] The command result callback
424424
* @return {Promise} returns Promise if no callback passed
425425
*/
426426
Collection.prototype.insertMany = function(docs, options, callback) {
@@ -652,6 +652,24 @@ define.classMethod('bulkWrite', {callback: true, promise:true});
652652
* @param {Collection~WriteOpResult} result The result object if the command was executed successfully.
653653
*/
654654

655+
/**
656+
* @typedef {Object} Collection~insertWriteOpResult
657+
* @property {Number} insertedCount The total amount of documents inserted.
658+
* @property {object[]} ops All the documents inserted using insertOne/insertMany/replaceOne. Documents contain the _id field if forceServerObjectId == false for insertOne/insertMany
659+
* @property {ObjectId[]} insertedIds All the generated _id's for the inserted documents.
660+
* @property {object} connection The connection object used for the operation.
661+
* @property {object} result The raw command result object returned from MongoDB (content might vary by server version).
662+
* @property {Number} result.ok Is 1 if the command executed correctly.
663+
* @property {Number} result.n The total count of documents inserted.
664+
*/
665+
666+
/**
667+
* The callback format for inserts
668+
* @callback Collection~insertWriteOpCallback
669+
* @param {MongoError} error An error instance representing the error during the execution.
670+
* @param {Collection~insertWriteOpResult} result The result object if the command was executed successfully.
671+
*/
672+
655673
/**
656674
* Inserts a single document or a an array of documents into MongoDB.
657675
* @method
@@ -662,7 +680,7 @@ define.classMethod('bulkWrite', {callback: true, promise:true});
662680
* @param {boolean} [options.j=false] Specify a journal write concern.
663681
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
664682
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
665-
* @param {Collection~writeOpCallback} [callback] The command result callback
683+
* @param {Collection~insertWriteOpCallback} [callback] The command result callback
666684
* @return {Promise} returns Promise if no callback passed
667685
* @deprecated Use insertOne, insertMany or bulkWrite
668686
*/
@@ -681,6 +699,27 @@ Collection.prototype.insert = function(docs, options, callback) {
681699

682700
define.classMethod('insert', {callback: true, promise:true});
683701

702+
/**
703+
* @typedef {Object} Collection~updateWriteOpResult
704+
* @property {Object} result The raw result returned from MongoDB, field will vary depending on server version.
705+
* @property {Number} result.ok Is 1 if the command executed correctly.
706+
* @property {Number} result.n The total count of documents scanned.
707+
* @property {Number} result.nModified The total count of documents modified.
708+
* @property {Object} connection The connection object used for the operation.
709+
* @property {Number} matchedCount The number of documents that matched the filter.
710+
* @property {Number} modifiedCount The number of documents that were modified.
711+
* @property {Number} upsertedCount The number of documents upserted.
712+
* @property {Object} upsertedId The upserted id.
713+
* @property {ObjectId} upsertedId._id The upserted _id returned from the server.
714+
*/
715+
716+
/**
717+
* The callback format for inserts
718+
* @callback Collection~updateWriteOpCallback
719+
* @param {MongoError} error An error instance representing the error during the execution.
720+
* @param {Collection~updateWriteOpResult} result The result object if the command was executed successfully.
721+
*/
722+
684723
/**
685724
* Update a single document on MongoDB
686725
* @method
@@ -691,7 +730,7 @@ define.classMethod('insert', {callback: true, promise:true});
691730
* @param {(number|string)} [options.w=null] The write concern.
692731
* @param {number} [options.wtimeout=null] The write concern timeout.
693732
* @param {boolean} [options.j=false] Specify a journal write concern.
694-
* @param {Collection~writeOpCallback} [callback] The command result callback
733+
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
695734
* @return {Promise} returns Promise if no callback passed
696735
*/
697736
Collection.prototype.updateOne = function(filter, update, options, callback) {
@@ -739,7 +778,7 @@ define.classMethod('updateOne', {callback: true, promise:true});
739778
* @param {(number|string)} [options.w=null] The write concern.
740779
* @param {number} [options.wtimeout=null] The write concern timeout.
741780
* @param {boolean} [options.j=false] Specify a journal write concern.
742-
* @param {Collection~writeOpCallback} [callback] The command result callback
781+
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
743782
* @return {Promise} returns Promise if no callback passed
744783
*/
745784
Collection.prototype.replaceOne = function(filter, update, options, callback) {
@@ -788,7 +827,7 @@ define.classMethod('replaceOne', {callback: true, promise:true});
788827
* @param {(number|string)} [options.w=null] The write concern.
789828
* @param {number} [options.wtimeout=null] The write concern timeout.
790829
* @param {boolean} [options.j=false] Specify a journal write concern.
791-
* @param {Collection~writeOpCallback} [callback] The command result callback
830+
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
792831
* @return {Promise} returns Promise if no callback passed
793832
*/
794833
Collection.prototype.updateMany = function(filter, update, options, callback) {
@@ -892,6 +931,22 @@ Collection.prototype.update = function(selector, document, options, callback) {
892931

893932
define.classMethod('update', {callback: true, promise:true});
894933

934+
/**
935+
* @typedef {Object} Collection~deleteWriteOpResult
936+
* @property {Object} result The raw result returned from MongoDB, field will vary depending on server version.
937+
* @property {Number} result.ok Is 1 if the command executed correctly.
938+
* @property {Number} result.n The total count of documents deleted.
939+
* @property {Object} connection The connection object used for the operation.
940+
* @property {Number} deletedCount The number of documents deleted.
941+
*/
942+
943+
/**
944+
* The callback format for inserts
945+
* @callback Collection~deleteWriteOpCallback
946+
* @param {MongoError} error An error instance representing the error during the execution.
947+
* @param {Collection~deleteWriteOpResult} result The result object if the command was executed successfully.
948+
*/
949+
895950
/**
896951
* Delete a document on MongoDB
897952
* @method
@@ -900,7 +955,7 @@ define.classMethod('update', {callback: true, promise:true});
900955
* @param {(number|string)} [options.w=null] The write concern.
901956
* @param {number} [options.wtimeout=null] The write concern timeout.
902957
* @param {boolean} [options.j=false] Specify a journal write concern.
903-
* @param {Collection~writeOpCallback} [callback] The command result callback
958+
* @param {Collection~deleteWriteOpCallback} [callback] The command result callback
904959
* @return {Promise} returns Promise if no callback passed
905960
*/
906961
Collection.prototype.deleteOne = function(filter, options, callback) {
@@ -945,7 +1000,7 @@ define.classMethod('removeOne', {callback: true, promise:true});
9451000
* @param {(number|string)} [options.w=null] The write concern.
9461001
* @param {number} [options.wtimeout=null] The write concern timeout.
9471002
* @param {boolean} [options.j=false] Specify a journal write concern.
948-
* @param {Collection~writeOpCallback} [callback] The command result callback
1003+
* @param {Collection~deleteWriteOpCallback} [callback] The command result callback
9491004
* @return {Promise} returns Promise if no callback passed
9501005
*/
9511006
Collection.prototype.deleteMany = function(filter, options, callback) {
@@ -1056,6 +1111,7 @@ define.classMethod('remove', {callback: true, promise:true});
10561111
* @param {boolean} [options.j=false] Specify a journal write concern.
10571112
* @param {Collection~writeOpCallback} [callback] The command result callback
10581113
* @return {Promise} returns Promise if no callback passed
1114+
* @deprecated use insertOne, insertMany, updateOne or updateMany
10591115
*/
10601116
Collection.prototype.save = function(doc, options, callback) {
10611117
var self = this;
@@ -1879,6 +1935,20 @@ var stats = function(self, options, callback) {
18791935

18801936
define.classMethod('stats', {callback: true, promise:true});
18811937

1938+
/**
1939+
* @typedef {Object} Collection~findAndModifyWriteOpResult
1940+
* @property {object} value Document returned from findAndModify command.
1941+
* @property {object} lastErrorObject The raw lastErrorObject returned from the command.
1942+
* @property {Number} ok Is 1 if the command executed correctly.
1943+
*/
1944+
1945+
/**
1946+
* The callback format for inserts
1947+
* @callback Collection~findAndModifyCallback
1948+
* @param {MongoError} error An error instance representing the error during the execution.
1949+
* @param {Collection~findAndModifyWriteOpResult} result The result object if the command was executed successfully.
1950+
*/
1951+
18821952
/**
18831953
* Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.
18841954
*
@@ -1888,7 +1958,7 @@ define.classMethod('stats', {callback: true, promise:true});
18881958
* @param {object} [options.projection=null] Limits the fields to return for all matching documents.
18891959
* @param {object} [options.sort=null] Determines which document the operation modifies if the query selects multiple documents.
18901960
* @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
1891-
* @param {Collection~resultCallback} [callback] The collection result callback
1961+
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
18921962
* @return {Promise} returns Promise if no callback passed
18931963
*/
18941964
Collection.prototype.findOneAndDelete = function(filter, options, callback) {
@@ -1937,7 +2007,7 @@ define.classMethod('findOneAndDelete', {callback: true, promise:true});
19372007
* @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
19382008
* @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
19392009
* @param {boolean} [options.returnOriginal=true] When false, returns the updated document rather than the original. The default is true.
1940-
* @param {Collection~resultCallback} [callback] The collection result callback
2010+
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
19412011
* @return {Promise} returns Promise if no callback passed
19422012
*/
19432013
Collection.prototype.findOneAndReplace = function(filter, replacement, options, callback) {
@@ -1988,7 +2058,7 @@ define.classMethod('findOneAndReplace', {callback: true, promise:true});
19882058
* @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
19892059
* @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
19902060
* @param {boolean} [options.returnOriginal=true] When false, returns the updated document rather than the original. The default is true.
1991-
* @param {Collection~resultCallback} [callback] The collection result callback
2061+
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
19922062
* @return {Promise} returns Promise if no callback passed
19932063
*/
19942064
Collection.prototype.findOneAndUpdate = function(filter, update, options, callback) {

lib/command_cursor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ inherits(CommandCursor, Readable);
142142
// Set the methods to inherit from prototype
143143
var methodsToInherit = ['_next', 'next', 'each', 'forEach', 'toArray'
144144
, 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed', 'kill'
145-
, '_find', '_getmore', '_killcursor', 'isDead', 'explain', 'isNotified'];
145+
, '_find', '_getmore', '_killcursor', 'isDead', 'explain', 'isNotified', 'isKilled'];
146146

147147
// Only inherit the types we need
148148
for(var i = 0; i < methodsToInherit.length; i++) {

lib/cursor.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ var define = Cursor.define = new Define('Cursor', Cursor, true);
176176
* @method
177177
* @param {Cursor~resultCallback} [callback] The result callback.
178178
* @throws {MongoError}
179-
* @deprecated
180179
* @return {Promise} returns Promise if no callback passed
181180
*/
182181
Cursor.prototype.hasNext = function(callback) {
@@ -208,7 +207,6 @@ define.classMethod('hasNext', {callback: true, promise:true});
208207
* @method
209208
* @param {Cursor~resultCallback} [callback] The result callback.
210209
* @throws {MongoError}
211-
* @deprecated
212210
* @return {Promise} returns Promise if no callback passed
213211
*/
214212
Cursor.prototype.next = function(callback) {

lib/db.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ var Db = function(databaseName, topology, options) {
188188
if(this.s.noListener) return;
189189

190190
// Add listeners
191-
topology.once('error', createListener(self, 'error', self));
192-
topology.once('timeout', createListener(self, 'timeout', self));
191+
topology.on('error', createListener(self, 'error', self));
192+
topology.on('timeout', createListener(self, 'timeout', self));
193193
topology.on('close', createListener(self, 'close', self));
194-
topology.once('parseError', createListener(self, 'parseError', self));
194+
topology.on('parseError', createListener(self, 'parseError', self));
195195
topology.once('open', createListener(self, 'open', self));
196196
topology.once('fullsetup', createListener(self, 'fullsetup', self));
197197
topology.once('all', createListener(self, 'all', self));
@@ -659,6 +659,7 @@ var evaluate = function(self, code, parameters, options, callback) {
659659
* @param {boolean} [options.nolock=false] Tell MongoDB not to block on the evaulation of the javascript.
660660
* @param {Db~resultCallback} [callback] The results callback
661661
* @return {Promise} returns Promise if no callback passed
662+
* @deprecated MongoDB 3.2 and higher no longer support eval.
662663
*/
663664
Db.prototype.eval = function(code, parameters, options, callback) {
664665
var self = this;
@@ -1631,47 +1632,65 @@ var createListener = function(self, e, object) {
16311632
/**
16321633
* Db close event
16331634
*
1635+
* Emitted after a socket closed against a single server or mongos proxy.
1636+
*
16341637
* @event Db#close
1635-
* @type {object}
1638+
* @type {MongoError}
16361639
*/
16371640

16381641
/**
16391642
* Db authenticated event
16401643
*
1644+
* Emitted after all server members in the topology (single server, replicaset or mongos) have successfully authenticated.
1645+
*
16411646
* @event Db#authenticated
16421647
* @type {object}
16431648
*/
16441649

16451650
/**
16461651
* Db reconnect event
16471652
*
1653+
* * Server: Emitted when the driver has reconnected and re-authenticated.
1654+
* * ReplicaSet: N/A
1655+
* * Mongos: Emitted when the driver reconnects and re-authenticates successfully against a Mongos.
1656+
*
16481657
* @event Db#reconnect
16491658
* @type {object}
16501659
*/
16511660

16521661
/**
16531662
* Db error event
16541663
*
1664+
* Emitted after an error occurred against a single server or mongos proxy.
1665+
*
16551666
* @event Db#error
16561667
* @type {MongoError}
16571668
*/
16581669

16591670
/**
16601671
* Db timeout event
16611672
*
1673+
* Emitted after a socket timeout occurred against a single server or mongos proxy.
1674+
*
16621675
* @event Db#timeout
1663-
* @type {object}
1676+
* @type {MongoError}
16641677
*/
16651678

16661679
/**
16671680
* Db parseError event
16681681
*
1682+
* The parseError event is emitted if the driver detects illegal or corrupt BSON being received from the server.
1683+
*
16691684
* @event Db#parseError
1670-
* @type {object}
1685+
* @type {MongoError}
16711686
*/
16721687

16731688
/**
1674-
* Db fullsetup event, emitted when all servers in the topology have been connected to.
1689+
* Db fullsetup event, emitted when all servers in the topology have been connected to at start up time.
1690+
*
1691+
* * Server: Emitted when the driver has connected to the single server and has authenticated.
1692+
* * ReplSet: Emitted after the driver has attempted to connect to all replicaset members.
1693+
* * Mongos: Emitted after the driver has attempted to connect to all mongos proxies.
16751694
*
16761695
* @event Db#fullsetup
16771696
* @type {Db}

lib/mongos.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ var Mongos = function(servers, options) {
195195

196196
// Last ismaster
197197
Object.defineProperty(this, 'numberOfConnectedServers', {
198-
enumerable:true, get: function() { return self.s.mongos.connectedServers().length; }
198+
enumerable:true, get: function() {
199+
return self.s.mongos.s.mongosState.connectedServers().length;
200+
}
199201
});
200202

201203
// BSON property

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb",
3-
"version": "2.0.41",
3+
"version": "2.0.42",
44
"description": "MongoDB legacy driver emulation layer on top of mongodb-core",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)