Socket
Socket
Sign inDemoInstall

mongodb

Package Overview
Dependencies
Maintainers
1
Versions
546
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb - npm Package Compare versions

Comparing version 0.9.6-11 to 0.9.6-12

4

lib/mongodb/collection.js

@@ -698,2 +698,4 @@ /**

Collection.prototype.findOne = function findOne (queryObject, options, callback) {
var self = this;
if ('function' === typeof queryObject) {

@@ -754,3 +756,3 @@ callback = queryObject;

if (!err && result.documents[0] && result.documents[0]['$err']) {
return callback(result.documents[0]['$err']);
return callback(self.db.wrap(result));
}

@@ -757,0 +759,0 @@

@@ -152,4 +152,3 @@ var BinaryParser = require('../bson/binary_parser').BinaryParser,

if(self.data.length() > 0) {
self.buildMongoObject(function(mongoObject) {
self.buildMongoObject(function(mongoObject) {
collection.insert(mongoObject, {safe:true}, function(err, collection) {

@@ -156,0 +155,0 @@ callback(null, self);

@@ -317,3 +317,3 @@ /**

} else {
if((self.currentChunk.position + string.length) > self.chunkSize) {
if((self.currentChunk.position + string.length) > self.chunkSize) {
var previousChunkNumber = self.currentChunk.chunkNumber;

@@ -323,6 +323,10 @@ var leftOverDataSize = self.chunkSize - self.currentChunk.position;

var leftOverData = string.substr(leftOverDataSize, (string.length - leftOverDataSize));
// Save out current Chunk as another variable and assign a new Chunk for overflow data
var saveChunk = self.currentChunk;
// Create a new chunk at once (avoid wrong writing of chunks)
self.currentChunk = new Chunk(self, {'n': (previousChunkNumber + 1)});
// Let's finish the current chunk and then call write again for the remaining data
self.currentChunk.write(previousChunkData, function(err, chunk) {
saveChunk.write(previousChunkData, function(err, chunk) {
chunk.save(function(err, result) {
self.currentChunk = new Chunk(self, {'n': (previousChunkNumber + 1)});
self.position = self.position + leftOverDataSize;

@@ -363,4 +367,3 @@ // Write the remaining data

callback(new Error((self.referenceBy == REFERENCE_BY_ID ? self.toHexString() : self.filename) + " not opened for writing"), null);
}
else {
} else {
if((self.currentChunk.position + buffer.length) > self.chunkSize) {

@@ -371,10 +374,12 @@ // Data exceeds current chunk remaining free size; fill up current chunk and write the rest

var leftOverDataSize = self.chunkSize - self.currentChunk.position;
var firstChunkData = buffer.slice(0, leftOverDataSize);
var firstChunkData = buffer.slice(0, leftOverDataSize);
var leftOverData = buffer.slice(leftOverDataSize);
// Save out current Chunk as another variable and assign a new Chunk for overflow data
var saveChunk = self.currentChunk;
// Create a new chunk at once (avoid wrong writing of chunks)
self.currentChunk = new Chunk(self, {'n': (previousChunkNumber + 1)});
// Let's finish the current chunk and then call write again for the remaining data
self.currentChunk.write(firstChunkData, function(err, chunk) {
saveChunk.write(firstChunkData, function(err, chunk) {
chunk.save(function(err, result) {
self.currentChunk = new Chunk(self, {'n': (previousChunkNumber + 1)});
self.position = self.position + leftOverDataSize;

@@ -717,13 +722,4 @@

// debug("===================================================================== read")
// debug(inspect(self.length))
// debug(inspect(self.position))
// debug(finalLength)
if((self.currentChunk.length() - self.currentChunk.position + 1 + finalBuffer.length) >= finalLength) {
// debug("---------------------------- finalLength :: " + finalLength)
finalBuffer = finalBuffer + self.currentChunk.read(finalLength - finalBuffer.length);
// debug("---------------------------- finalLength :: " + finalBuffer.length)
self.position = finalBuffer.length;

@@ -730,0 +726,0 @@ callback(null, finalBuffer);

{ "name" : "mongodb"
, "description" : "A node.js driver for MongoDB"
, "keywords" : ["mongodb", "mongo", "driver", "db"]
, "version" : "0.9.6-11"
, "version" : "0.9.6-12"
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>"

@@ -6,0 +6,0 @@ , "contributors" : [ "Aaron Heckmann",

var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var testCase = require('../deps/nodeunit').testCase,
debug = require('util').debug
debug = require('util').debug,
inspect = require('util').inspect,

@@ -261,2 +261,34 @@ nodeunit = require('../deps/nodeunit'),

});
},
shouldHandleAssertionError : function(test) {
client.createCollection('test_handle_assertion_error', function(err, r) {
client.collection('test_handle_assertion_error', function(err, collection) {
collection.insert({a:{lat:50, lng:10}}, {safe: true}, function(err, docs) {
test.ok(err == null);
var query = {a:{$within:{$box:[[1,-10],[80,120]]}}};
// We don't have a geospatial index at this point
collection.findOne(query, function(err, docs) {
test.ok(err instanceof Error);
collection.ensureIndex([['a', '2d' ]], true, function(err, indexName) {
test.ok(err == null);
collection.findOne(query, function(err, doc) {
test.ok(err == null);
var invalidQuery = {a:{$within:{$box:[[-10,-180],[10,180]]}}};
collection.findOne(invalidQuery, function(err, doc) {
test.ok(err instanceof Error);
test.done();
});
});
});
});
});
});
});
}

@@ -263,0 +295,0 @@ })

@@ -13,2 +13,3 @@ var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();

Chunk = mongodb.Chunk,
Step = require("../../deps/step/lib/step");
Server = mongodb.Server;

@@ -48,3 +49,109 @@

},
shouldCorrectlyWriteLargeFileStringAndReadBack : function(test) {
var db = client;
var fileId = new client.bson_serializer.ObjectID();
var gridStore = new GridStore(db, fileId, "w", {root:'fs'});
gridStore.chunkSize = 5000;
gridStore.open(function(err, gridStore) {
Step(
function writeData() {
var group = this.group();
var d = '';
for(var j = 0; j < 5000;j++) {
d = d + '+';
}
for(var i = 0; i < 15000; i += 5000) {
gridStore.write(d, false, group());
}
},
function readAsStream() {
gridStore.close(function(err, result) {
var gotEnd = false;
var endLen = 0;
var gridStore = new GridStore(db, fileId, "r");
gridStore.open(function(err, gridStore) {
var stream = gridStore.stream(true);
stream.on("data", function(chunk) {
endLen += chunk.length
// Test length of chunk
test.equal(5000, chunk.length);
// Check each chunk's data
for(var i = 0; i < 5000; i++) test.equal('+', String.fromCharCode(chunk[i]));
});
stream.on("end", function() {
gotEnd = true;
});
stream.on("close", function() {
test.equal(15000, endLen);
test.equal(true, gotEnd);
test.done();
});
});
});
}
)
});
},
shouldCorrectlyWriteLargeFileBufferAndReadBack : function(test) {
var db = client;
var fileId = new client.bson_serializer.ObjectID();
var gridStore = new GridStore(db, fileId, "w", {root:'fs'});
gridStore.chunkSize = 5000;
gridStore.open(function(err, gridStore) {
Step(
function writeData() {
var group = this.group();
var d = new Buffer(5000);
for(var j = 0; j < 5000;j++) {
d[j] = 43;
}
for(var i = 0; i < 15000; i += 5000) {
gridStore.write(d, false, group());
}
},
function readAsStream() {
gridStore.close(function(err, result) {
var gotEnd = false;
var endLen = 0;
var gridStore = new GridStore(db, fileId, "r");
gridStore.open(function(err, gridStore) {
var stream = gridStore.stream(true);
stream.on("data", function(chunk) {
endLen += chunk.length
// Test length of chunk
test.equal(5000, chunk.length);
// Check each chunk's data
for(var i = 0; i < 5000; i++) test.equal('+', String.fromCharCode(chunk[i]));
});
stream.on("end", function() {
gotEnd = true;
});
stream.on("close", function() {
test.equal(15000, endLen);
test.equal(true, gotEnd);
test.done();
});
});
});
}
)
});
},
shouldCorrectlyReadFileUsingStream : function(test) {

@@ -54,6 +161,6 @@ var gridStoreR = new GridStore(client, "test_gs_read_stream", "r");

var data = fs.readFileSync("./test/gridstore/test_gs_weird_bug.png", 'binary');
var readLen = 0;
var gotEnd = 0;
gridStoreW.open(function(err, gs) {

@@ -60,0 +167,0 @@ gs.write(data, function(err, gs) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc