Skip to content

Commit

Permalink
fixes for passing down of promoteLongs
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Aug 21, 2016
1 parent 7c1846c commit f5217bc
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 25 deletions.
18 changes: 12 additions & 6 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ var Collection = function(db, topology, dbName, name, pkFactory, options) {
var internalHint = null;
var opts = options != null && ('object' === typeof options) ? options : {};
var slaveOk = options == null || options.slaveOk == null ? db.slaveOk : options.slaveOk;
var serializeFunctions = options == null || options.serializeFunctions == null ? db.serializeFunctions : options.serializeFunctions;
var raw = options == null || options.raw == null ? db.raw : options.raw;
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 readPreference = null;
var collectionHint = null;
var namespace = f("%s.%s", dbName, name);
Expand Down Expand Up @@ -106,12 +107,14 @@ var Collection = function(db, topology, dbName, name, pkFactory, options) {
, namespace: namespace
// Read preference
, readPreference: readPreference
// Raw
, raw: raw
// SlaveOK
, slaveOk: slaveOk
// Serialize functions
, serializeFunctions: serializeFunctions
// Raw
, raw: raw
// promoteLongs
, promoteLongs: promoteLongs
// internalHint
, internalHint: internalHint
// collectionHint
Expand Down Expand Up @@ -341,11 +344,14 @@ Collection.prototype.find = function() {
newOptions.promiseLibrary = this.s.promiseLibrary;

// Set raw if available at collection level
if(newOptions.raw == null && this.s.raw) newOptions.raw = this.s.raw;
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;

// Sort options
if(findCommand.sort)
if(findCommand.sort) {
findCommand.sort = formattedOrderClause(findCommand.sort);
}

// Set the readConcern
if(this.s.readConcern) {
Expand Down
8 changes: 0 additions & 8 deletions lib/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ define.classMethod('skip', {callback: false, promise:false, returns: [Cursor]});
Cursor.prototype.nextObject = Cursor.prototype.next;

var nextObject = function(self, callback) {
// console.log("cursor:: nextObject")
if(self.s.state == Cursor.CLOSED || self.isDead && self.isDead()) return handleCallback(callback, MongoError.create({message: "Cursor is closed", driver:true}));
if(self.s.state == Cursor.INIT && self.s.cmd.sort) {
try {
Expand Down Expand Up @@ -841,17 +840,13 @@ Cursor.prototype.toArray = function(callback) {
var toArray = function(self, callback) {
var items = [];

// console.log("!!!!!!!!!!!!! toArray :: 0")
// Reset cursor
self.rewind();
self.s.state = Cursor.INIT;
// console.log("!!!!!!!!!!!!! toArray :: 1")

// Fetch all the documents
var fetchDocs = function() {
// console.log("!!!!!!!!!!!!! toArray :: 2")
self._next(function(err, doc) {
// console.log("!!!!!!!!!!!!! toArray :: 3")
if(err) return handleCallback(callback, err);
if(doc == null) {
self.s.state = Cursor.CLOSED;
Expand Down Expand Up @@ -1057,16 +1052,13 @@ Cursor.prototype.explain = function(callback) {
define.classMethod('explain', {callback: true, promise:true});

Cursor.prototype._read = function(n) {
// console.log("=== _read")
var self = this;
if(self.s.state == Cursor.CLOSED || self.isDead()) {
return self.push(null);
}

// Get the next item
self.nextObject(function(err, result) {
// console.log("=== _read 1")
// console.dir(err)
if(err) {
if(self.listeners('error') && self.listeners('error').length > 0) {
self.emit('error', err);
Expand Down
2 changes: 1 addition & 1 deletion lib/mongos.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var release = os.release();
, 'store', 'auto_reconnect', 'autoReconnect', 'emitError'
, 'keepAlive', 'noDelay', 'connectTimeoutMS', 'socketTimeoutMS'
, 'loggerLevel', 'logger', 'reconnectTries', 'appname', 'domainsEnabled'
, 'servername'];
, 'servername', 'promoteLongs'];

/**
* Creates a new Mongos instance
Expand Down
2 changes: 1 addition & 1 deletion lib/replset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
, 'servername', 'promoteLongs'];

// Get package.json variable
var driverVersion = require(__dirname + '/../package.json').version;
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var release = os.release();
, 'keepAlive', 'noDelay', 'connectTimeoutMS', 'socketTimeoutMS'
, 'loggerLevel', 'logger', 'reconnectTries', 'reconnectInterval', 'monitoring'
, 'appname', 'domainsEnabled'
, 'servername'];
, 'servername', 'promoteLongs'];

/**
* Creates a new Server instance
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"es6-promise": "3.2.1",
"mongodb-core": "2.0.9",
"mongodb-core": "christkv/mongodb-core#2.0",
"readable-stream": "2.1.5"
},
"devDependencies": {
Expand Down
6 changes: 2 additions & 4 deletions test/functional/insert_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1466,8 +1466,6 @@ exports.handleBSONTypeInsertsCorrectly = {
test.ok(doc.maxkey instanceof MaxKey);

collection.findOne({"code": new Code("function () {}", {a: 77})}, function(err, doc) {
console.dir(err)
console.dir(doc)
test.equal(null, err);
test.ok(doc != null);
db.close();
Expand Down Expand Up @@ -1728,7 +1726,7 @@ exports.shouldCorrectlyHonorPromoteLongFalseNativeBSON = {

var o = configuration.writeConcernMax();
o.promoteLongs = false;
var db = configuration.newDbInstance(o, {native_parser:true})
var db = configuration.newDbInstance(o, {native_parser:true, promoteLongs: false})
db.open(function(err, db) {
db.collection('shouldCorrectlyHonorPromoteLong').insert({
doc: Long.fromNumber(10)
Expand Down Expand Up @@ -1759,6 +1757,7 @@ exports.shouldCorrectlyHonorPromoteLongFalseNativeBSONWithGetMore = {

var o = configuration.writeConcernMax();
o.promoteLongs = false;
// var db = configuration.newDbInstance(o, {native_parser:true, promoteLongs:false})
var db = configuration.newDbInstance(o, {native_parser:true})
db.open(function(err, db) {
db.collection('shouldCorrectlyHonorPromoteLongFalseNativeBSONWithGetMore').insertMany([
Expand Down Expand Up @@ -2135,7 +2134,6 @@ exports['Correctly allow forceServerObjectId for insertOne'] = {
test.equal(null, err);

db.collection('apm_test').insertOne({a:1}, {forceServerObjectId:true}).then(function(r) {
// console.dir(r)
test.equal(null, err);
test.equal(undefined, started[0].command.documents[0]._id);
listener.uninstrument();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/sharding_read_preference_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ exports['Should correctly connect to MongoS using single server instance'] = {
collection.insert({test:1}, {w:'majority', wtimeout:10000}, function(err, result) {
test.equal(null, err);

collection.findOne({test:1}, {}, {readPreference:new ReadPreference(ReadPreference.SECONDARY, [{"dc2":"sf"}, {"dc1":"ny"}])}, function(err, item) {
collection.findOne({test:1}, {}, {readPreference:new ReadPreference(ReadPreference.SECONDARY)}, function(err, item) {
test.equal(null, err);
test.equal(1, item.test);

Expand Down
5 changes: 2 additions & 3 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,8 @@ if(argv.t == 'functional') {

return new mongo.Mongos([
new mongo.Server(host, port, options)
]);
}, manager: new ShardingManager({
})
], options);
}, manager: new ShardingManager({})
}

executeTestSuite(config);
Expand Down

0 comments on commit f5217bc

Please sign in to comment.