diff --git a/HISTORY.md b/HISTORY.md index a0f6d1e393..7368bf2a0d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,9 @@ +2.2.8 2016-08-23 +---------------- +* Updated mongodb-core to 2.0.10. +* Added promoteValues flag (default to true) to allow user to specify they only want wrapped BSON values back instead of promotion to native types. +* Do not close mongos proxy connection on failed ismaster check in ha process (Issue #130). + 2.2.7 2016-08-19 ---------------- * If only a single mongos is provided in the seedlist, fix issue where it would be assigned as single standalone server instead of mongos topology (Issue #130). diff --git a/index.js b/index.js index ed138a2a33..5808750fac 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,7 @@ connect.Code = core.BSON.Code; connect.Map = core.BSON.Map; connect.DBRef = core.BSON.DBRef; connect.Double = core.BSON.Double; +connect.Int32 = core.BSON.Int32; connect.Long = core.BSON.Long; connect.MinKey = core.BSON.MinKey; connect.MaxKey = core.BSON.MaxKey; diff --git a/lib/collection.js b/lib/collection.js index 4edf29fe0a..3bea23683a 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -65,7 +65,8 @@ var Collection = function(db, topology, dbName, name, pkFactory, options) { var slaveOk = options == null || options.slaveOk == null ? db.slaveOk : options.slaveOk; var serializeFunctions = options == null || options.serializeFunctions == null ? db.s.options.serializeFunctions : options.serializeFunctions; var raw = options == null || options.raw == null ? db.s.options.raw : options.raw; - var promoteLongs = options == null || options.raw == null ? db.s.options.promoteLongs : options.promoteLongs; + var promoteLongs = options == null || options.promoteLongs == null ? db.s.options.promoteLongs : options.promoteLongs; + var promoteValues = options == null || options.raw == promoteValues ? db.s.options.promoteValues : options.promoteValues; var readPreference = null; var collectionHint = null; var namespace = f("%s.%s", dbName, name); @@ -115,6 +116,8 @@ var Collection = function(db, topology, dbName, name, pkFactory, options) { , raw: raw // promoteLongs , promoteLongs: promoteLongs + // promoteValues + , promoteValues: promoteValues // internalHint , internalHint: internalHint // collectionHint @@ -347,6 +350,7 @@ Collection.prototype.find = function() { if(newOptions.raw == null && typeof this.s.raw == 'boolean') newOptions.raw = this.s.raw; // Set promoteLongs if available at collection level if(newOptions.promoteLongs == null && typeof this.s.promoteLongs == 'boolean') newOptions.promoteLongs = this.s.promoteLongs; + if(newOptions.promoteValues == null && typeof this.s.promoteValues == 'boolean') newOptions.promoteValues = this.s.promoteValues; // Sort options if(findCommand.sort) { diff --git a/lib/db.js b/lib/db.js index ea1177f338..86d80ef7a9 100644 --- a/lib/db.js +++ b/lib/db.js @@ -24,7 +24,7 @@ var EventEmitter = require('events').EventEmitter , assign = require('./utils').assign; var debugFields = ['authSource', 'w', 'wtimeout', 'j', 'native_parser', 'forceServerObjectId' - , 'serializeFunctions', 'raw', 'promoteLongs', 'bufferMaxEntries', 'numberOfRetries', 'retryMiliSeconds' + , 'serializeFunctions', 'raw', 'promoteLongs', 'promoteValues', 'bufferMaxEntries', 'numberOfRetries', 'retryMiliSeconds' , 'readPreference', 'pkFactory', 'parentDb', 'promiseLibrary', 'noListener']; /** @@ -64,6 +64,7 @@ var legalOptionNames = ['w', 'wtimeout', 'fsync', 'j', 'readPreference', 'readPr * @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. * @param {boolean} [options.raw=false] Return document results as raw BSON buffers. * @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution. + * @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types. * @param {number} [options.bufferMaxEntries=-1] Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited. * @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). * @param {object} [options.pkFactory=null] A primary key factory object for generation of custom _id keys. diff --git a/lib/mongos.js b/lib/mongos.js index bd3ac3b787..703edbdde8 100644 --- a/lib/mongos.js +++ b/lib/mongos.js @@ -54,7 +54,7 @@ var release = os.release(); , 'store', 'auto_reconnect', 'autoReconnect', 'emitError' , 'keepAlive', 'noDelay', 'connectTimeoutMS', 'socketTimeoutMS' , 'loggerLevel', 'logger', 'reconnectTries', 'appname', 'domainsEnabled' - , 'servername', 'promoteLongs']; + , 'servername', 'promoteLongs', 'promoteValues']; /** * Creates a new Mongos instance diff --git a/lib/replset.js b/lib/replset.js index 590858e958..3845847247 100644 --- a/lib/replset.js +++ b/lib/replset.js @@ -49,7 +49,7 @@ var legalOptionNames = ['ha', 'haInterval', 'replicaSet', 'rs_name', 'secondaryA , 'store', 'auto_reconnect', 'autoReconnect', 'emitError' , 'keepAlive', 'noDelay', 'connectTimeoutMS', 'socketTimeoutMS', 'strategy', 'debug' , 'loggerLevel', 'logger', 'reconnectTries', 'appname', 'domainsEnabled' - , 'servername', 'promoteLongs']; + , 'servername', 'promoteLongs', 'promoteValues']; // Get package.json variable var driverVersion = require(__dirname + '/../package.json').version; diff --git a/lib/server.js b/lib/server.js index d50eefe3fa..586f8f7764 100644 --- a/lib/server.js +++ b/lib/server.js @@ -51,7 +51,7 @@ var release = os.release(); , 'keepAlive', 'noDelay', 'connectTimeoutMS', 'socketTimeoutMS' , 'loggerLevel', 'logger', 'reconnectTries', 'reconnectInterval', 'monitoring' , 'appname', 'domainsEnabled' - , 'servername', 'promoteLongs']; + , 'servername', 'promoteLongs', 'promoteValues']; /** * Creates a new Server instance diff --git a/package.json b/package.json index ff0cb4e003..10c8f0828d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongodb", - "version": "2.2.7", + "version": "2.2.8", "description": "The official MongoDB driver for Node.js", "main": "index.js", "repository": { @@ -14,8 +14,7 @@ ], "dependencies": { "es6-promise": "3.2.1", - "mongodb-core": "2.0.9", - "mongodb-core": "christkv/mongodb-core#2.0", + "mongodb-core": "2.0.10", "readable-stream": "2.1.5" }, "devDependencies": { diff --git a/test/functional/promote_values_tests.js b/test/functional/promote_values_tests.js new file mode 100644 index 0000000000..c896ff25c5 --- /dev/null +++ b/test/functional/promote_values_tests.js @@ -0,0 +1,112 @@ +exports['should correctly honor promoteValues when creating an instance using Db'] = { + // Add a tag that our runner can trigger on + // in this case we are setting that node needs to be higher than 0.10.X to run + metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } }, + + // The actual test we wish to run + test: function(configuration, test) { + var Long = configuration.require.Long, + Int32 = configuration.require.Int32, + Double = configuration.require.Double; + + var o = configuration.writeConcernMax(); + var db = configuration.newDbInstance(o, {native_parser:true, promoteValues: false}) + db.open(function(err, db) { + db.collection('shouldCorrectlyHonorPromoteValues').insert({ + doc: Long.fromNumber(10) + , int: 10 + , double: 2.2222 + , array: [[Long.fromNumber(10)]] + }, function(err, doc) { + test.equal(null, err); + + db.collection('shouldCorrectlyHonorPromoteValues').findOne(function(err, doc) { + test.equal(null, err); + + test.deepEqual(Long.fromNumber(10), doc.doc); + test.deepEqual(new Int32(10), doc.int); + test.deepEqual(new Double(2.2222), doc.double); + + db.close(); + test.done(); + }); + }); + }); + } +} + +exports['should correctly honor promoteValues when creating an instance using MongoClient'] = { + // Add a tag that our runner can trigger on + // in this case we are setting that node needs to be higher than 0.10.X to run + metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } }, + + // The actual test we wish to run + test: function(configuration, test) { + var Long = configuration.require.Long, + Int32 = configuration.require.Int32, + Double = configuration.require.Double, + MongoClient = configuration.require.MongoClient; + + MongoClient.connect(configuration.url(), { + promoteValues: false, + }, function(err, db) { + db.collection('shouldCorrectlyHonorPromoteValues').insert({ + doc: Long.fromNumber(10) + , int: 10 + , double: 2.2222 + , array: [[Long.fromNumber(10)]] + }, function(err, doc) { + test.equal(null, err); + + db.collection('shouldCorrectlyHonorPromoteValues').findOne(function(err, doc) { + test.equal(null, err); + + test.deepEqual(Long.fromNumber(10), doc.doc); + test.deepEqual(new Int32(10), doc.int); + test.deepEqual(new Double(2.2222), doc.double); + + db.close(); + test.done(); + }); + }); + }); + } +} + +exports['should correctly honor promoteValues at cursor level'] = { + // Add a tag that our runner can trigger on + // in this case we are setting that node needs to be higher than 0.10.X to run + metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } }, + + // The actual test we wish to run + test: function(configuration, test) { + var Long = configuration.require.Long, + Int32 = configuration.require.Int32, + Double = configuration.require.Double, + MongoClient = configuration.require.MongoClient; + + MongoClient.connect(configuration.url(), { + promoteValues: false, + }, function(err, db) { + db.collection('shouldCorrectlyHonorPromoteValues').insert({ + doc: Long.fromNumber(10) + , int: 10 + , double: 2.2222 + , array: [[Long.fromNumber(10)]] + }, function(err, doc) { + test.equal(null, err); + + db.collection('shouldCorrectlyHonorPromoteValues').find().next(function(err, doc) { + test.equal(null, err); + + test.deepEqual(Long.fromNumber(10), doc.doc); + test.deepEqual(new Int32(10), doc.int); + test.deepEqual(new Double(2.2222), doc.double); + + db.close(); + test.done(); + }); + }); + }); + } +} diff --git a/test/runner.js b/test/runner.js index 94fa6a4135..2595bf311b 100644 --- a/test/runner.js +++ b/test/runner.js @@ -300,6 +300,7 @@ var testFiles = [ , '/test/functional/find_and_modify_tests.js' , '/test/functional/hang_tests.js', , '/test/functional/disconnect_handler_tests.js', + , '/test/functional/promote_values_tests.js', // Replicaset tests , '/test/functional/replset_read_preference_tests.js'