Comparing version 0.9.7-2-2 to 0.9.7-2-3
@@ -79,2 +79,4 @@ /** | ||
ObjectID.prototype.toHexString = function() { | ||
if(this.__id) return this.__id; | ||
var hexString = '' | ||
@@ -92,3 +94,3 @@ , number | ||
return hexString; | ||
return this.__id = hexString; | ||
}; | ||
@@ -143,2 +145,8 @@ | ||
/** | ||
* Returns the Date that his ID was generated. | ||
* | ||
* @return {Date} | ||
*/ | ||
ObjectID.prototype.getTimestamp = function() { | ||
@@ -145,0 +153,0 @@ var timestamp = new Date(); |
@@ -17,3 +17,3 @@ /** | ||
**/ | ||
const eErrorMessages = /E\d{5}/; | ||
const eErrorMessages = /No matching object found/; | ||
@@ -615,3 +615,3 @@ /** | ||
callback(self.db.wrap(result[0]), null); | ||
} else if(result[0].errmsg != null && result[0].errmsg.match(eErrorMessages)) { | ||
} else if(result[0].errmsg != null && !result[0].errmsg.match(eErrorMessages)) { | ||
// Workaround due to 1.8.X returning an error on no matching object | ||
@@ -660,3 +660,3 @@ // while 2.0.X does not not, making 2.0.X behaviour standard | ||
// backwards compat for options object | ||
var test = ['limit','sort','fields','skip','hint','explain','snapshot','timeout','tailable', 'batchSize', 'raw'] | ||
var test = ['limit','sort','fields','skip','hint','explain','snapshot','timeout','tailable', 'batchSize', 'raw', 'read'] | ||
, is_option = false; | ||
@@ -738,9 +738,9 @@ | ||
var o = options; | ||
// callback for backward compatibility | ||
if (callback) { | ||
// TODO refactor Cursor args | ||
callback(null, new Cursor(this.db, this, selector, fields, o.skip, o.limit, o.sort, o.hint, o.explain, o.snapshot, o.timeout, o.tailable, o.batchSize, o.slaveOk, o.raw)); | ||
callback(null, new Cursor(this.db, this, selector, fields, o.skip, o.limit, o.sort, o.hint, o.explain, o.snapshot, o.timeout, o.tailable, o.batchSize, o.slaveOk, o.raw, o.read)); | ||
} else { | ||
return new Cursor(this.db, this, selector, fields, o.skip, o.limit, o.sort, o.hint, o.explain, o.snapshot, o.timeout, o.tailable, o.batchSize, o.slaveOk, o.raw); | ||
return new Cursor(this.db, this, selector, fields, o.skip, o.limit, o.sort, o.hint, o.explain, o.snapshot, o.timeout, o.tailable, o.batchSize, o.slaveOk, o.raw, o.read); | ||
} | ||
@@ -747,0 +747,0 @@ }; |
@@ -169,4 +169,2 @@ var utils = require('./connection_utils'), | ||
if(clearListeners && self.connection != null) { | ||
// console.log("------------------------------------------------------") | ||
// console.log(self.connection.removeAllListeners.toString()) | ||
var keys = Object.keys(self.eventHandlers); | ||
@@ -173,0 +171,0 @@ // Remove all listeners |
@@ -109,6 +109,3 @@ var Connection = require('./connection').Connection, | ||
, get: function() { | ||
console.log("-------------------------------------------------------------------------") | ||
var servers = this.allServerInstances(); | ||
console.dir(servers) | ||
return servers[0].dbInstances; | ||
@@ -115,0 +112,0 @@ } |
@@ -202,2 +202,4 @@ var Connection = require('./connection').Connection, | ||
var firstResult = mongoReply && mongoReply.documents; | ||
// console.log("===========================================================") | ||
// console.dir(firstResult) | ||
// Check for an error, if we have one let's trigger the callback and clean up | ||
@@ -204,0 +206,0 @@ // The chained callbacks |
@@ -34,2 +34,4 @@ var QueryCommand = require('./commands/query_command').QueryCommand, | ||
* with {@link Cursor#batchSize} after performing the initial query to the database. | ||
* @param raw {?boolean} Return all query documents as raw buffers (default false) | ||
* @param read {?boolean} Specify override of read from source (primary/secondary) | ||
* | ||
@@ -44,3 +46,3 @@ * @see Cursor#toArray | ||
*/ | ||
var Cursor = exports.Cursor = function(db, collection, selector, fields, skip, limit, sort, hint, explain, snapshot, timeout, tailable, batchSize, slaveOk, raw) { | ||
var Cursor = exports.Cursor = function(db, collection, selector, fields, skip, limit, sort, hint, explain, snapshot, timeout, tailable, batchSize, slaveOk, raw, read) { | ||
this.db = db; | ||
@@ -61,3 +63,4 @@ this.collection = collection; | ||
this.raw = raw == null ? false : raw; | ||
this.read = read == null ? true : read; | ||
this.totalNumberOfRecords = 0; | ||
@@ -485,3 +488,3 @@ this.items = []; | ||
self.db._executeQueryCommand(cmd, {read:true, raw:self.raw}, commandHandler); | ||
self.db._executeQueryCommand(cmd, {read:self.read, raw:self.raw}, commandHandler); | ||
commandHandler = null; | ||
@@ -520,3 +523,3 @@ } else if(self.items.length) { | ||
// Execute the command | ||
self.db._executeQueryCommand(getMoreCommand, {read:true, raw:self.raw}, function(err, result) { | ||
self.db._executeQueryCommand(getMoreCommand, {read:self.read, raw:self.raw}, function(err, result) { | ||
try { | ||
@@ -604,3 +607,3 @@ if(err != null) callback(err, null); | ||
function execute(command) { | ||
self.db._executeQueryCommand(command, {read:true, raw:self.raw}, function(err,result) { | ||
self.db._executeQueryCommand(command, {read:self.read, raw:self.raw}, function(err,result) { | ||
if(err) { | ||
@@ -672,3 +675,3 @@ stream.emit('error', err); | ||
var command = new KillCursorCommand(this.db, [this.cursorId]); | ||
this.db._executeQueryCommand(command, {read:true, raw:self.raw}, null); | ||
this.db._executeQueryCommand(command, {read:self.read, raw:self.raw}, null); | ||
} catch(err) {} | ||
@@ -675,0 +678,0 @@ } |
@@ -780,3 +780,2 @@ var QueryCommand = require('./commands/query_command').QueryCommand, | ||
var __executeQueryCommand = function(self, db_command, options, callback) { | ||
// console.log("-------------------- __executeQueryCommand") | ||
// Options unpacking | ||
@@ -790,6 +789,4 @@ var read = options['read'] != null ? options['read'] : false; | ||
if(callback instanceof Function && !onAll) { | ||
// // Let's the out outgoing request Id | ||
// var requestId = db_command.getRequestId().toString(); | ||
// Fetch either a reader or writer dependent on the specified read option | ||
var connection = read ? self.serverConfig.checkoutReader() : self.serverConfig.checkoutWriter(); | ||
var connection = read == true || read === 'secondary' ? self.serverConfig.checkoutReader() : self.serverConfig.checkoutWriter(); | ||
// Override connection if needed | ||
@@ -799,3 +796,2 @@ connection = specifiedConnection != null ? specifiedConnection : connection; | ||
if(connection == null) { | ||
// console.log("-----------------------------------------------__executeQueryCommand :: 0 :: [no open connections]") | ||
return callback(new Error("no open connections")); | ||
@@ -833,3 +829,2 @@ } | ||
if(connection == null) { | ||
// console.log("-----------------------------------------------__executeQueryCommand :: 1 :: [no open connections]") | ||
return callback(new Error("no open connections")); | ||
@@ -860,6 +855,4 @@ } | ||
} else { | ||
// // Let's the out outgoing request Id | ||
// var requestId = db_command.getRequestId().toString(); | ||
// Fetch either a reader or writer dependent on the specified read option | ||
var connection = read ? self.serverConfig.checkoutReader() : self.serverConfig.checkoutWriter(); | ||
var connection = read == true || read === 'secondary' ? self.serverConfig.checkoutReader() : self.serverConfig.checkoutWriter(); | ||
// Override connection if needed | ||
@@ -866,0 +859,0 @@ connection = specifiedConnection != null ? specifiedConnection : connection; |
@@ -47,16 +47,12 @@ var Long = require('../goog/math/long').Long, | ||
if(this.messageLength > docLimitSize) { | ||
var batches = 1; | ||
var batchSize = this.numberReturned; | ||
var overflow = 0; | ||
// Just walk down until we get a positive number >= 1 | ||
for(var i = 50; i > 0; i--) { | ||
for(var i = 10; i > 0; i--) { | ||
if((this.numberReturned/i) >= 1) { | ||
batchSize = i; | ||
batches = Math.floor(this.numberReturned/i); | ||
overflow = this.numberReturned%i; | ||
break; | ||
} | ||
} | ||
// Actual main creator of the processFunction setting internal state to control the flow | ||
@@ -63,0 +59,0 @@ var parseFunction = function(_self, _binary_reply, _batchSize, _numberReturned) { |
{ "name" : "mongodb" | ||
, "description" : "A node.js driver for MongoDB" | ||
, "keywords" : ["mongodb", "mongo", "driver", "db"] | ||
, "version" : "0.9.7-2-2" | ||
, "version" : "0.9.7-2-3" | ||
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "contributors" : [ "Aaron Heckmann", |
@@ -7,2 +7,4 @@ Install | ||
npm install mongodb | ||
That may give you a warning telling you that bugs['web'] should be bugs['url'], it would be safe to ignore it (this has been fixed in the development version) | ||
@@ -361,3 +363,3 @@ To install from the latest from the repository, run:: | ||
If your company could benefit from a even better-engineered node.js mongodb driver I would appreciate any type of sponsorship you may be able to provide. All the sponsors will get a lifetime display in this readme, priority support and help on problems and votes on the roadmap decisions for the driver. If you are interested contact me on [christkv@gmail.com](mailto:christkv@gmail.com) for details. | ||
If your company could benefit from a even better-engineered node.js mongodb driver I would appreciate any type of sponsorship you may be able to provide. All the sponsors will get a lifetime display in this readme, priority support and help on problems and votes on the roadmap decisions for the driver. If you are interested contact me on [christkv AT g m a i l.com](mailto:christkv@gmail.com) for details. | ||
@@ -364,0 +366,0 @@ And I'm very thankful for code contributions. If you are interested in working on features please contact me so we can discuss API design and testing. |
@@ -356,3 +356,3 @@ var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure(); | ||
}, | ||
'Should Correctly Serialize and Deserialize Oid' : function(test) { | ||
@@ -362,11 +362,12 @@ var doc = {doc: new BSONSE.ObjectID()}; | ||
var serialized_data = BSONSE.BSON.serialize(doc, false, true); | ||
var serialized_data2 = new Buffer(BSONSE.BSON.calculateObjectSize(doc)); | ||
BSONSE.BSON.serializeWithBufferAndIndex(doc, false, serialized_data2, 0); | ||
BSONSE.BSON.serializeWithBufferAndIndex(doc, false, serialized_data2, 0); | ||
assertBuffersEqual(test, serialized_data, serialized_data2, 0); | ||
delete doc.doc.__id; | ||
test.deepEqual(doc, BSONDE.BSON.deserialize(serialized_data)); | ||
test.done(); | ||
test.done(); | ||
}, | ||
'Should Correctly encode Empty Hash' : function(test) { | ||
@@ -1131,2 +1132,2 @@ var doc = {}; | ||
// Assign out tests | ||
module.exports = tests; | ||
module.exports = tests; |
@@ -1078,2 +1078,20 @@ var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure(); | ||
}, | ||
shouldCorrectlyReturnErrorFromMongodbOnFindAndModifyForcedError : function(test) { | ||
client.createCollection('shouldCorrectlyReturnErrorFromMongodbOnFindAndModifyForcedError', function(err, collection) { | ||
var q = { x: 1 }; | ||
var set = { y:2, _id: new client.bson_serializer.ObjectID() }; | ||
var opts = { new: true, upsert: true }; | ||
// Original doc | ||
var doc = {_id: new client.bson_serializer.ObjectID(), x:1}; | ||
// Insert original doc | ||
collection.insert(doc, {safe:true}, function(err, result) { | ||
collection.findAndModify(q, [], set, opts, function (err, res) { | ||
test.ok(err != null); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
}, | ||
@@ -1080,0 +1098,0 @@ // shouldCorrectlyExecuteFindAndModifyUnderConcurrentLoad : function(test) { |
@@ -19,7 +19,9 @@ #!/usr/bin/env node | ||
res.header('Content-Type', 'application/json'); | ||
if(err == null) { | ||
if(typeof allCount == "undefined") | ||
if(typeof allCount == "undefined") { | ||
res.send({data: data, success: true}); | ||
else | ||
} else { | ||
res.send({allCount: allCount, data: data, success: true}); | ||
} | ||
} else { | ||
@@ -92,3 +94,3 @@ util.log(util.inspect(err)); | ||
target = new mongo.Server(config.host, config.port, {'auto_reconnect':true, 'poolSize':4}); | ||
db = new mongo.Db(dbname, target); | ||
db = new mongo.Db(dbname, target, {native_parser:false}); | ||
db.open(callback); | ||
@@ -147,4 +149,3 @@ } | ||
options, | ||
function(err, docs, allCount) | ||
{ | ||
function(err, docs, allCount) { | ||
app.renderResponse(res, err, docs, allCount); | ||
@@ -154,2 +155,2 @@ }); | ||
app.listen(9999); | ||
app.listen(9999, '127.0.0.1'); |
@@ -48,2 +48,48 @@ var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure(); | ||
shouldCorrectlyEmitErrorOnAllDbsOnPoolClose : function(test) { | ||
if(process.platform !== 'linux') { | ||
var db = new Db('tests', new Server("127.0.0.1", 27027, {auto_reconnect: true}), {native_parser: (process.env['TEST_NATIVE'] != null)}); | ||
// All inserted docs | ||
var docs = []; | ||
var errs = []; | ||
var insertDocs = []; | ||
var numberOfCloses = 0; | ||
// Start server | ||
var serverManager = new ServerManager({auth:false, purgedirectories:true, journal:false, start_port:27027}) | ||
serverManager.start(false, function() { | ||
db.on("close", function(err) { | ||
numberOfCloses = numberOfCloses + 1; | ||
}) | ||
db.open(function(err, db) { | ||
db.createCollection('shouldCorrectlyErrorOnAllDbs', function(err, collection) { | ||
test.equal(null, err); | ||
collection.insert({a:1}, {safe:true}, function(err, result) { | ||
test.equal(null, err); | ||
// Open a second db | ||
var db2 = db.db('tests_2'); | ||
// Add a close handler | ||
db2.on("close", function(err) { | ||
numberOfCloses = numberOfCloses + 1; | ||
}); | ||
db.serverConfig.connectionPool.openConnections[0].connection.destroy(); | ||
// Kill server and end test | ||
serverManager.stop(9, function() { | ||
test.equal(2, numberOfCloses) | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} else { | ||
test.done(); | ||
} | ||
}, | ||
// Test the auto connect functionality of the db | ||
@@ -140,45 +186,3 @@ shouldCorrectlyUseSameConnectionsForTwoDifferentDbs : function(test) { | ||
}, | ||
shouldCorrectlyEmitErrorOnAllDbsOnPoolClose : function(test) { | ||
var db = new Db('tests', new Server("127.0.0.1", 27027, {auto_reconnect: true}), {native_parser: (process.env['TEST_NATIVE'] != null)}); | ||
// All inserted docs | ||
var docs = []; | ||
var errs = []; | ||
var insertDocs = []; | ||
var numberOfCloses = 0; | ||
// Start server | ||
var serverManager = new ServerManager({auth:false, purgedirectories:true, journal:true, start_port:27027}) | ||
serverManager.start(false, function() { | ||
db.on("close", function(err) { | ||
numberOfCloses = numberOfCloses + 1; | ||
}) | ||
db.open(function(err, db) { | ||
db.createCollection('shouldCorrectlyErrorOnAllDbs', function(err, collection) { | ||
test.equal(null, err); | ||
collection.insert({a:1}, {safe:true}, function(err, result) { | ||
test.equal(null, err); | ||
// Open a second db | ||
var db2 = db.db('tests_2'); | ||
// Add a close handler | ||
db2.on("close", function(err) { | ||
numberOfCloses = numberOfCloses + 1; | ||
}); | ||
db.serverConfig.connectionPool.openConnections[0].connection.destroy(); | ||
// Kill server and end test | ||
serverManager.stop(9, function() { | ||
test.equal(2, numberOfCloses) | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}, | ||
// run this last | ||
@@ -185,0 +189,0 @@ noGlobalsLeaked: function(test) { |
@@ -169,3 +169,3 @@ var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false; | ||
}, | ||
shouldCorrectlyQuerySecondaries : function(test) { | ||
@@ -200,2 +200,36 @@ // debug("=========================================== shouldCorrectlyQuerySecondaries") | ||
shouldAllowToForceReadWithPrimary : function(test) { | ||
// debug("=========================================== shouldAllowToForceReadWithPrimary") | ||
// Replica configuration | ||
var replSet = new ReplSetServers( [ | ||
new Server( RS.host, RS.ports[0], { auto_reconnect: true } ), | ||
], | ||
{rs_name:RS.name, read_secondary:true} | ||
); | ||
// Insert some data | ||
var db = new Db('integration_test_', replSet); | ||
db.open(function(err, p_db) { | ||
if(err != null) debug("shouldReadPrimary :: " + inspect(err)); | ||
// Create a collection | ||
p_db.createCollection('shouldAllowToForceReadWithPrimary', function(err, collection) { | ||
test.equal(null, err); | ||
// Insert a document | ||
collection.insert({a:1}, {safe:{w:2, wtimeout:10000}}, function(err, result) { | ||
test.equal(null, err); | ||
// Force read using primary | ||
var cursor = collection.find({}, {read:'primary'}) | ||
// Get documents | ||
cursor.toArray(function(err, items) { | ||
test.equal(1, items.length); | ||
test.equal(1, items[0].a); | ||
p_db.close(); | ||
test.done(); | ||
}) | ||
}); | ||
}) | ||
}) | ||
}, | ||
noGlobalsLeaked : function(test) { | ||
@@ -202,0 +236,0 @@ var leaks = gleak.detectNew(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1895352
30832
400
221