Socket
Socket
Sign inDemoInstall

mongodb

Package Overview
Dependencies
Maintainers
1
Versions
562
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 1.1.3 to 1.1.4

60

lib/mongodb/collection.js

@@ -634,25 +634,43 @@ /**

// Commands to send
var commands = [];
// Add the find and modify command
commands.push(DbCommand.createDbCommand(this.db, queryObject, options));
// If we have safe defined we need to return both call results
var chainedCommands = errorOptions != null ? true : false;
// Add error command if we have one
if(chainedCommands) {
commands.push(DbCommand.createGetLastErrorCommand(errorOptions, this.db));
}
// If we have j, w or something else do the getLast Error path
if(errorOptions != null && typeof errorOptions == 'object') {
// Commands to send
var commands = [];
// Add the find and modify command
commands.push(DbCommand.createDbCommand(this.db, queryObject, options));
// If we have safe defined we need to return both call results
var chainedCommands = errorOptions != null ? true : false;
// Add error command if we have one
if(chainedCommands) {
commands.push(DbCommand.createGetLastErrorCommand(errorOptions, this.db));
}
// Fire commands and
this.db._executeQueryCommand(commands, {read:false}, function(err, result) {
result = result && result.documents;
// console.dir(errorOptions)
// commands = DbCommand.createDbCommand(this.db, queryObject, options)
// Fire commands and
this.db._executeQueryCommand(commands, {read:false}, function(err, result) {
if(err != null) return callback(err);
result = result && result.documents;
if(err != null) return callback(err);
if(result[0].err != null) return callback(self.db.wrap(result[0]), null);
// Workaround due to 1.8.X returning an error on no matching object
// while 2.0.X does not not, making 2.0.X behaviour standard
if(result[0].errmsg != null && !result[0].errmsg.match(eErrorMessages))
return callback(self.db.wrap(result[0]), null, result[0]);
return callback(null, result[0].value, result[0]);
});
if(result[0].err != null) return callback(self.db.wrap(result[0]), null);
// Workaround due to 1.8.X returning an error on no matching object
// while 2.0.X does not not, making 2.0.X behaviour standard
if(result[0].errmsg != null && !result[0].errmsg.match(eErrorMessages))
return callback(self.db.wrap(result[0]), null, result[0]);
return callback(null, result[0].value, result[0]);
});
} else {
// Only run command and rely on getLastError command
var command = DbCommand.createDbCommand(this.db, queryObject, options)
// Execute command
this.db._executeQueryCommand(command, {read:false}, function(err, result) {
if(err != null) return callback(err);
result = result && result.documents;
if(result[0].errmsg != null && !result[0].errmsg.match(eErrorMessages))
return callback(self.db.wrap(result[0]), null, result[0]);
// If we have an error return it
if(result[0].lastErrorObject && result[0].lastErrorObject.err != null) return callback(self.db.wrap(result[0].lastErrorObject), null);
return callback(null, result[0].value, result[0]);
});
}
}

@@ -659,0 +677,0 @@

@@ -37,2 +37,3 @@ var Connection = require('./connection').Connection,

* - **secondaryAcceptableLatencyMS** {Number, default:15}, sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms)
* - **connectArbiter** {Boolean, default:false}, sets if the driver should connect to arbiters or not.
*

@@ -72,2 +73,5 @@ * @class Represents a Replicaset Configuration

// Connect arbiters ?
this.connectArbiter = this.options.connectArbiter == null ? false : this.options.connectArbiter;
// Default poolSize for new server instances

@@ -150,8 +154,8 @@ this.poolSize = this.options.poolSize == null ? 5 : this.options.poolSize;

}
// var deduplicate list
var uniqueServers = {};
var uniqueServers = {};
// De-duplicate any servers in the seed list
for(var i = 0; i < this.servers.length; i++) {
var server = this.servers[i];
var server = this.servers[i];
// If server does not exist set it

@@ -162,3 +166,3 @@ if(uniqueServers[server.host + ":" + server.port] == null) {

}
// Let's set the deduplicated list of servers

@@ -169,3 +173,3 @@ this.servers = [];

this.servers.push(uniqueServers[key]);
}
}

@@ -325,2 +329,5 @@ // Enabled ha

&& null == serversToConnectList[member['name']]) {
if (member['stateStr'] == 'ARBITER' && self.connectArbiter != true) {
continue;
}
// Split the server string

@@ -413,3 +420,3 @@ var parts = member.name.split(/:/);

var _handler = function(event, self) {
return function(err, server) {
return function(err, server) {
// Check if we have a secondary server

@@ -420,5 +427,5 @@ if(self._state.master && self._state.master.name == server.name) {

// Error out all callbacks
__executeAllCallbacksWithError(self.db, err);
} else if(self._state.master
&& (self._state.secondaries[server.name] != null
__executeAllCallbacksWithError(self.db, err);
} else if(self._state.master
&& (self._state.secondaries[server.name] != null
|| self._state.arbiters[server.name] != null

@@ -432,3 +439,3 @@ || self._state.passives[server.name] != null)) {

}
// If it's a primary we need to close the set to reconnect

@@ -474,5 +481,5 @@ if(self._state.master && self._state.master.host == server.host && self._state.master.port == server.port) {

// Emit a connection error
return self.emit("connectionError",
return self.emit("connectionError",
new Error("configured mongodb replicaset does not match provided replicaset [" + setName + "] != [" + self.replicaSet + "]"))
}
}

@@ -482,3 +489,3 @@ // Make sure we have the right reference

self._state.addresses[me] = instanceServer;
// Let's add the server to our list of server types

@@ -505,11 +512,14 @@ if(secondary == true && (passive == false || passive == null)) {

instanceServer.on("timeout", _handler("timeout", self));
// Possible hosts
var possibleHosts = Array.isArray(hosts) ? hosts.slice() : [];
possibleHosts = Array.isArray(passives) ? possibleHosts.concat(passives) : possibleHosts;
possibleHosts = Array.isArray(arbiters) ? possibleHosts.concat(arbiters) : possibleHosts;
if(self.connectArbiter == true) {
possibleHosts = Array.isArray(arbiters) ? possibleHosts.concat(arbiters) : possibleHosts;
}
if(Array.isArray(candidateServers)) {
// Add any new candidate servers for connection
for(var j = 0; j < possibleHosts.length; j++) {
for(var j = 0; j < possibleHosts.length; j++) {
if(self._state.addresses[possibleHosts[j]] == null && possibleHosts[j] != null) {

@@ -520,3 +530,3 @@ var parts = possibleHosts[j].split(/:/);

}
// New candidate server

@@ -529,3 +539,3 @@ var candidateServer = new Server(parts[0], parseInt(parts[1]));

}
}
}
}

@@ -537,3 +547,3 @@ } else if(err != null || self._serverState == 'disconnected'){

}
// Attempt to connect to the next server

@@ -552,3 +562,3 @@ if(Array.isArray(candidateServers) && candidateServers.length > 0) {

// If ssl is specified
if(self.ssl) serverConnections[i].ssl = true;
if(self.ssl) serverConnections[i].ssl = true;
// Set fast connect timeout

@@ -558,7 +568,7 @@ socketOptions['connectTimeoutMS'] = self._connectTimeoutMS

socketOptions['host'] = server.host;
socketOptions['port'] = server.port;
socketOptions['port'] = server.port;
server.socketOptions = socketOptions;
server.replicasetInstance = self;
server.enableRecordQueryStats(self.recordQueryStats);
// Set the server

@@ -574,9 +584,9 @@ addresses[server.host + ":" + server.port] = server;

// Emit a connection error
return self.emit("connectionError",
new Error("no primary server found in set"))
return self.emit("connectionError",
new Error("no primary server found in set"))
} else{
self.emit("fullsetup", null, self.db, self);
self.emit("fullsetup", null, self.db, self);
self.emit("open", null, self.db, self);
}
}
}
}

@@ -589,7 +599,7 @@ }

ReplSet.prototype.connect = function(parent, options, callback) {
var self = this;
var self = this;
if('function' === typeof options) callback = options, options = {};
if(options == null) options = {};
if(!('function' === typeof callback)) callback = null;
// Ensure it's all closed

@@ -605,9 +615,9 @@ self.close();

parent.slaveOk = this.slaveOk ? this.slaveOk : parent.slaveOk;
// Remove any listeners
this.removeAllListeners("fullsetup");
this.removeAllListeners("connectionError");
// Add primary found event handler
this.once("fullsetup", function() {
this.once("fullsetup", function() {
// Set state connected

@@ -622,6 +632,6 @@ self._serverState = 'connected';

callback = null;
internalCallback(null, parent, self);
internalCallback(null, parent, self);
}
});
this.once("connectionError", function(err) {

@@ -635,6 +645,6 @@ self._serverState = 'disconnected';

callback = null;
internalCallback(err, parent, self);
internalCallback(err, parent, self);
}
});
// Get server addresses

@@ -651,12 +661,13 @@ var addresses = this._state.addresses;

// If ssl is specified
if(this.ssl) serverConnections[i].ssl = true;
if(this.ssl) serverConnections[i].ssl = true;
// Set fast connect timeout
socketOptions['connectTimeoutMS'] = this._connectTimeoutMS
// De-duplicate any servers
var server;
for(var i = 0; i < this.servers.length; i++) {
var server = this.servers[i];
server = this.servers[i];
// Add host information to socket options
socketOptions['host'] = server.host;
socketOptions['port'] = server.port;
socketOptions['port'] = server.port;
server.socketOptions = socketOptions;

@@ -670,3 +681,3 @@ server.replicasetInstance = this;

}
// Get the list of servers that is deduplicated and start connecting

@@ -677,5 +688,5 @@ var candidateServers = [];

}
// Let's connect to the first one on the list
server.connect(parent, {returnIsMasterResults: true, eventReceiver:server}, _connectHandler(this, candidateServers, candidateServers.pop()));
server = candidateServers.pop();
server.connect(parent, {returnIsMasterResults: true, eventReceiver:server}, _connectHandler(this, candidateServers, server));
}

@@ -787,3 +798,3 @@

finalReadPreference = finalReadPreference == true ? ReadPreference.SECONDARY_PREFERRED : finalReadPreference;
// If we are reading from a primary

@@ -961,5 +972,5 @@ if(finalReadPreference == 'primary') {

this._state.addresses[key].close();
}
}
}
// If it's a callback

@@ -966,0 +977,0 @@ if(typeof callback == 'function') callback(null, null);

@@ -51,3 +51,8 @@ /**

// Call stream constructor
Stream.call(this);
if(typeof Stream == 'function') {
Stream.call(this);
} else {
// 0.4.X backward compatibility fix
Stream.Stream.call(this);
}

@@ -101,3 +106,8 @@ // Handle options

*/
GridStore.prototype = { __proto__: Stream.prototype }
if(typeof Stream == 'function') {
GridStore.prototype = { __proto__: Stream.prototype }
} else {
// Node 0.4.X compatibility code
GridStore.prototype = { __proto__: Stream.Stream.prototype }
}

@@ -104,0 +114,0 @@ // Move pipe to _pipe

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

@@ -78,3 +78,3 @@ , "contributors" : [ "Aaron Heckmann",

, "directories" : { "lib" : "./lib/mongodb" }
, "engines" : { "node" : ">=0.4.0" }
, "engines" : { "node" : ">=0.6.0" }
, "scripts": { "test" : "make test_pure" }

@@ -81,0 +81,0 @@ , "licenses" : [ { "type" : "Apache License, Version 2.0"

Sorry, the diff of this file is too big to display

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