Comparing version 0.9.8-6 to 0.9.8-7
@@ -1,13 +0,13 @@ | ||
var BSON = require('../lib/mongodb').BSONNative.BSON, | ||
ObjectID = require('../lib/mongodb').BSONNative.ObjectID, | ||
Code = require('../lib/mongodb').BSONNative.Code, | ||
var BSON = require('../../lib/mongodb').BSONNative.BSON, | ||
ObjectID = require('../../lib/mongodb').BSONNative.ObjectID, | ||
Code = require('../../lib/mongodb').BSONNative.Code, | ||
debug = require('util').debug, | ||
inspect = require('util').inspect, | ||
mongodb = require('../lib/mongodb'), | ||
mongodb = require('../../lib/mongodb'), | ||
Db = mongodb.Db, | ||
Server = mongodb.Server, | ||
Step = require("../deps/step/lib/step"); | ||
Step = require("../../deps/step/lib/step"); | ||
var BSON = require('../lib/mongodb').BSONPure.BSON, | ||
ObjectID = require('../lib/mongodb').BSONPure.ObjectID; | ||
var BSON = require('../../lib/mongodb').BSONPure.BSON, | ||
ObjectID = require('../../lib/mongodb').BSONPure.ObjectID; | ||
@@ -17,57 +17,59 @@ // Open the db connection | ||
db.dropCollection('hammer_collection', function(err, result) { | ||
var i = 0; | ||
// Fire random command | ||
setInterval(function() { | ||
var command = Math.round(Math.random() * 4); | ||
// command = 1; | ||
db.admin().authenticate('admin', 'admin', function(err, result) { | ||
var i = 0; | ||
// Fire random command | ||
setInterval(function() { | ||
var command = Math.round(Math.random() * 4); | ||
// command = 1; | ||
// debug("================= execute :: " + i++ + " = " + command) | ||
// debug("================= execute :: " + i++ + " = " + command) | ||
// Execute the command | ||
if(command == 1) { | ||
// Execute an insert | ||
db.collection('hammer_collection', function(err, collection) { | ||
collection.insert(randomDoc(), {safe:false}, function(err, result) { | ||
debug("---------------------------------------- INSERT") | ||
// Execute the command | ||
if(command == 1) { | ||
// Execute an insert | ||
db.collection('hammer_collection', function(err, collection) { | ||
collection.insert(randomDoc(), {safe:false}, function(err, result) { | ||
debug("---------------------------------------- INSERT") | ||
}); | ||
}); | ||
}); | ||
} else if(command == 2) { | ||
// Update some random record | ||
db.collection('hammer_collection', function(err, collection) { | ||
collection.findOne({}, function(err, item) { | ||
if(!err && item != null) { | ||
// Grab key before we bork it | ||
var _id = item._id; | ||
var keys = Object.keys(item); | ||
var objLength = keys.length; | ||
var pickRandomItem = Math.round(Math.random() * objLength); | ||
// Show a random doc in | ||
item[keys[pickRandomItem]] = randomDoc(); | ||
// Update doc | ||
collection.update({'_id':_id}, item, {safe:false}, function(err, result) { | ||
debug("---------------------------------------- UPDATE") | ||
}); | ||
} | ||
} else if(command == 2) { | ||
// Update some random record | ||
db.collection('hammer_collection', function(err, collection) { | ||
collection.findOne({}, function(err, item) { | ||
if(!err && item != null) { | ||
// Grab key before we bork it | ||
var _id = item._id; | ||
var keys = Object.keys(item); | ||
var objLength = keys.length; | ||
var pickRandomItem = Math.round(Math.random() * objLength); | ||
// Show a random doc in | ||
item[keys[pickRandomItem]] = randomDoc(); | ||
// Update doc | ||
collection.update({'_id':_id}, item, {safe:false}, function(err, result) { | ||
debug("---------------------------------------- UPDATE") | ||
}); | ||
} | ||
}) | ||
}); | ||
} else if(command == 3) { | ||
// Update some random record | ||
db.collection('hammer_collection', function(err, collection) { | ||
collection.findOne({}, function(err, item) { | ||
if(!err && item != null) { | ||
// Update doc | ||
collection.remove({'_id':item._id}, {safe:false}, function(err, result) { | ||
debug("---------------------------------------- REMOVE") | ||
}); | ||
} | ||
}) | ||
}); | ||
} else if(command == 4) { | ||
db.collection('hammer_collection', function(err, collection) { | ||
collection.find().limit(100).toArray(function(err, items) { | ||
debug("---------------------------------------- QUERY :: " + items.length) | ||
}) | ||
}) | ||
}); | ||
} else if(command == 3) { | ||
// Update some random record | ||
db.collection('hammer_collection', function(err, collection) { | ||
collection.findOne({}, function(err, item) { | ||
if(!err && item != null) { | ||
// Update doc | ||
collection.remove({'_id':item._id}, {safe:false}, function(err, result) { | ||
debug("---------------------------------------- REMOVE") | ||
}); | ||
} | ||
}) | ||
}); | ||
} else if(command == 4) { | ||
db.collection('hammer_collection', function(err, collection) { | ||
collection.find().limit(100).toArray(function(err, items) { | ||
debug("---------------------------------------- QUERY :: " + items.length) | ||
}) | ||
}) | ||
} | ||
}, 0); | ||
} | ||
}, 0); | ||
}) | ||
}); | ||
@@ -74,0 +76,0 @@ }); |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,6 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
sys = require("sys"); | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -7,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Admin = require('../lib/mongodb').Admin, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ Connection = require('../lib/mongodb').Connection, |
@@ -1,5 +0,1 @@ | ||
GLOBAL.DEBUG = true; | ||
test = require("assert"); | ||
var Db = require('../lib/mongodb').Db, | ||
@@ -6,0 +2,0 @@ connect = require('../lib/mongodb').connect; |
@@ -112,3 +112,5 @@ /** | ||
case 'object': | ||
if(value instanceof ObjectID) { | ||
if(value == null || value instanceof MinKey || value instanceof MaxKey || value['_bsontype'] == 'MinKey' || value['_bsontype'] == 'MaxKey') { | ||
return (name != null ? (Buffer.byteLength(name) + 1) : 0) + (1); | ||
} else if(value instanceof ObjectID || value['_bsontype'] == 'ObjectID') { | ||
return (name != null ? (Buffer.byteLength(name) + 1) : 0) + (12 + 1); | ||
@@ -119,5 +121,6 @@ } else if(value instanceof Date) { | ||
return (name != null ? (Buffer.byteLength(name) + 1) : 0) + (1 + 4 + 1) + value.length; | ||
} else if(value instanceof Long || value instanceof Double || value instanceof Timestamp) { | ||
} else if(value instanceof Long || value instanceof Double || value instanceof Timestamp | ||
|| value['_bsontype'] == 'Long' || value['_bsontype'] == 'Double' || value['_bsontype'] == 'Timestamp') { | ||
return (name != null ? (Buffer.byteLength(name) + 1) : 0) + (8 + 1); | ||
} else if(value instanceof Code) { | ||
} else if(value instanceof Code || value['_bsontype'] == 'Code') { | ||
// Calculate size depending on the availability of a scope | ||
@@ -129,9 +132,7 @@ if(value.scope != null && Object.keys(value.scope).length > 0) { | ||
} | ||
} else if(value == null || value instanceof MinKey || value instanceof MaxKey) { | ||
return (name != null ? (Buffer.byteLength(name) + 1) : 0) + (1); | ||
} else if(value instanceof Binary) { | ||
} else if(value instanceof Binary || value['_bsontype'] == 'Binary') { | ||
return (name != null ? (Buffer.byteLength(name) + 1) : 0) + (value.position + 1 + 4 + 1); | ||
} else if(value instanceof Symbol) { | ||
} else if(value instanceof Symbol || value['_bsontype'] == 'Symbol') { | ||
return (name != null ? (Buffer.byteLength(name) + 1) : 0) + (Buffer.byteLength(value.value, 'utf8') + 4 + 1 + 1); | ||
} else if(value instanceof DBRef) { | ||
} else if(value instanceof DBRef || value['_bsontype'] == 'DBRef') { | ||
// Set up correct object for serialization | ||
@@ -313,3 +314,18 @@ var ordered_values = { | ||
case 'object': | ||
if(value instanceof ObjectID) { | ||
if(value === null || value instanceof MinKey || value instanceof MaxKey | ||
|| value['_bsontype'] == 'MinKey' || value['_bsontype'] == 'MaxKey') { | ||
// Write the type of either min or max key | ||
if(value === null) { | ||
buffer[index++] = BSON.BSON_DATA_NULL; | ||
} else if(value instanceof MinKey) { | ||
buffer[index++] = BSON.BSON_DATA_MIN_KEY; | ||
} else { | ||
buffer[index++] = BSON.BSON_DATA_MAX_KEY; | ||
} | ||
// Encode the name | ||
index = index + buffer.write(name, index, 'utf8') + 1; | ||
buffer[index - 1] = 0; | ||
return index; | ||
} else if(value instanceof ObjectID || value['_bsontype'] == 'ObjectID') { | ||
// Write the type | ||
@@ -367,3 +383,3 @@ buffer[index++] = BSON.BSON_DATA_OID; | ||
return index; | ||
} else if(value instanceof Long || value instanceof Timestamp) { | ||
} else if(value instanceof Long || value instanceof Timestamp || value['_bsontype'] == 'Long' || value['_bsontype'] == 'Timestamp') { | ||
// Write the type | ||
@@ -388,3 +404,3 @@ buffer[index++] = value instanceof Long ? BSON.BSON_DATA_LONG : BSON.BSON_DATA_TIMESTAMP; | ||
return index; | ||
} else if(value instanceof Double) { | ||
} else if(value instanceof Double || value['_bsontype'] == 'Double') { | ||
// Encode as double | ||
@@ -400,3 +416,3 @@ buffer[index++] = BSON.BSON_DATA_NUMBER; | ||
return index; | ||
} else if(value instanceof Code) { | ||
} else if(value instanceof Code || value['_bsontype'] == 'Code') { | ||
if(value.scope != null && Object.keys(value.scope).length > 0) { | ||
@@ -479,17 +495,3 @@ // Write the type | ||
} | ||
} else if(value === null || value instanceof MinKey || value instanceof MaxKey) { | ||
// Write the type of either min or max key | ||
if(value === null) { | ||
buffer[index++] = BSON.BSON_DATA_NULL; | ||
} else if(value instanceof MinKey) { | ||
buffer[index++] = BSON.BSON_DATA_MIN_KEY; | ||
} else { | ||
buffer[index++] = BSON.BSON_DATA_MAX_KEY; | ||
} | ||
// Encode the name | ||
index = index + buffer.write(name, index, 'utf8') + 1; | ||
buffer[index - 1] = 0; | ||
return index; | ||
} else if(value instanceof Binary) { | ||
} else if(value instanceof Binary || value['_bsontype'] == 'Binary') { | ||
// Write the type | ||
@@ -516,3 +518,3 @@ buffer[index++] = BSON.BSON_DATA_BINARY; | ||
return index; | ||
} else if(value instanceof Symbol) { | ||
} else if(value instanceof Symbol || value['_bsontype'] == 'Symbol') { | ||
// Write the type | ||
@@ -537,3 +539,3 @@ buffer[index++] = BSON.BSON_DATA_SYMBOL; | ||
return index; | ||
} else if(value instanceof DBRef) { | ||
} else if(value instanceof DBRef || value['_bsontype'] == 'DBRef') { | ||
// Write the type | ||
@@ -540,0 +542,0 @@ buffer[index++] = BSON.BSON_DATA_OBJECT; |
@@ -777,3 +777,3 @@ /** | ||
// callback for backward compatibility | ||
if (callback) { | ||
if(callback) { | ||
// TODO refactor Cursor args | ||
@@ -864,98 +864,6 @@ callback(null, new Cursor(this.db, this, selector, fields, o.skip, o.limit | ||
var self = this; | ||
var options | ||
, args = Array.prototype.slice.call(arguments, 0) | ||
, has_callback = typeof args[args.length - 1] === 'function' | ||
, has_weird_callback = typeof args[0] === 'function' | ||
, callback = has_callback ? args.pop() : (has_weird_callback ? args.shift() : null) | ||
, len = args.length | ||
, selector = len >= 1 ? args[0] : {} | ||
, fields = len >= 2 ? args[1] : undefined; | ||
if (len === 1 && has_weird_callback) { | ||
// backwards compat for callback?, options case | ||
selector = {}; | ||
options = args[0]; | ||
} | ||
if (len === 2) { | ||
// backwards compat for options object | ||
var test = ['limit','sort','fields','skip','hint','explain','snapshot','timeout','tailable', 'batchSize', 'raw'] | ||
, is_option = false; | ||
for (var idx = 0, l = test.length; idx < l; ++idx) { | ||
if (test[idx] in fields) { | ||
is_option = true; | ||
break; | ||
} | ||
} | ||
if (is_option) { | ||
options = fields; | ||
fields = undefined; | ||
} else { | ||
options = {}; | ||
} | ||
} | ||
if (3 === len) { | ||
options = args[2]; | ||
} | ||
// Ensure selector is not null | ||
selector = selector == null ? {} : selector; | ||
// Validate correctness off the selector | ||
var object = selector; | ||
if(object instanceof Buffer) { | ||
var object_size = object[0] | object[1] << 8 | object[2] << 16 | object[3] << 24; | ||
if(object_size != object.length) { | ||
var error = new Error("query selector raw message size does not match message header size [" + object.length + "] != [" + object_size + "]"); | ||
error.name = 'MongoError'; | ||
throw error; | ||
} | ||
} | ||
// Validate correctness of the field selector | ||
var object = fields; | ||
if(object instanceof Buffer) { | ||
var object_size = object[0] | object[1] << 8 | object[2] << 16 | object[3] << 24; | ||
if(object_size != object.length) { | ||
var error = new Error("query fields raw message size does not match message header size [" + object.length + "] != [" + object_size + "]"); | ||
error.name = 'MongoError'; | ||
throw error; | ||
} | ||
} | ||
// Check special case where we are using an objectId | ||
if(selector instanceof ObjectID) { | ||
selector = {_id:selector}; | ||
} | ||
// If it's a serialized fields field we need to just let it through | ||
// user be warned it better be good | ||
if (options && options.fields && !(options.fields instanceof Buffer)) { | ||
fields = {}; | ||
if (Array.isArray(options.fields)) { | ||
if (!options.fields.length) { | ||
fields['_id'] = 1; | ||
} else { | ||
for (var i = 0, l = options.fields.length; i < l; i++) { | ||
fields[options.fields[i]] = 1; | ||
} | ||
} | ||
} else { | ||
fields = options.fields; | ||
} | ||
} | ||
if (!options) options = {}; | ||
options.skip = len > 3 ? args[2] : options.skip ? options.skip : 0; | ||
options.limit = 1; | ||
options.raw = options.raw != null && typeof options.raw === 'boolean' ? options.raw : this.raw; | ||
options.hint = options.hint != null ? normalizeHintField(options.hint) : this.internalHint; | ||
options.timeout = len == 5 ? args[4] : typeof options.timeout === 'undefined' ? undefined : options.timeout; | ||
// If we have overridden slaveOk otherwise use the default db setting | ||
options.slaveOk = options.slaveOk != null ? options.slaveOk : this.db.slaveOk; | ||
// Create cursor instance | ||
var o = options; | ||
var cursor = new Cursor(this.db, this, selector, fields, o.skip, 1, o.sort, o.hint, o.explain, o.snapshot, o.timeout, o.tailable, o.batchSize, o.slaveOk, o.raw); | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
var callback = args.pop(); | ||
var cursor = this.find.apply(this, args).limit(1).batchSize(1); | ||
// Return the item | ||
cursor.toArray(function(err, items) { | ||
@@ -962,0 +870,0 @@ if(err != null) return callback(err instanceof Error ? err : self.db.wrap(new Error(err)), null); |
@@ -9,3 +9,3 @@ var BinaryParser = require('../bson/binary_parser').BinaryParser, | ||
/** | ||
* Class for representing a signle chunk in GridFS. | ||
* Class for representing a single chunk in GridFS. | ||
* | ||
@@ -12,0 +12,0 @@ * @class |
{ "name" : "mongodb" | ||
, "description" : "A node.js driver for MongoDB" | ||
, "keywords" : ["mongodb", "mongo", "driver", "db"] | ||
, "version" : "0.9.8-6" | ||
, "version" : "0.9.8-7" | ||
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "contributors" : [ "Aaron Heckmann", |
@@ -253,4 +253,4 @@ var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure(); | ||
try { | ||
collection.findOne(illegalBuffer).toArray(function() {}) | ||
} catch(err) { | ||
collection.findOne(illegalBuffer, function() {}) | ||
} catch(err) { | ||
test.ok(err.toString().indexOf("query selector") != -1); | ||
@@ -260,3 +260,3 @@ } | ||
try { | ||
collection.findOne({}, illegalBuffer).toArray(function() {}) | ||
collection.findOne({}, illegalBuffer, function() {}) | ||
} catch(err) { | ||
@@ -263,0 +263,0 @@ test.ok(err.toString().indexOf("query fields") != -1); |
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
2747559
46711