Socket
Socket
Sign inDemoInstall

mongodb-core

Package Overview
Dependencies
Maintainers
1
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-core - npm Package Compare versions

Comparing version 1.1.33 to 1.2.0

simple_2_document_limit_toArray.dat

7

HISTORY.md

@@ -0,1 +1,8 @@

1.2.0 06-17-2015
-----------------
- Switching to using the 0.4.x pure JS serializer, removing dependency on C++ parser.
- Refactoring wire protocol messages to avoid expensive size calculations of documents in favor of writing out an array of buffers to the sockets.
- NODE-486 fixed issue related to limit and skip when calling toArray in 2.0 driver.
- NODE-483 throw error if capabilities of topology is queries before topology has performed connection setup.
1.1.33 05-31-2015

@@ -2,0 +9,0 @@ -----------------

170

lib/connection/commands.js

@@ -58,3 +58,3 @@ "use strict";

this.numberToReturn = options.numberToReturn || 0;
this.returnFieldSelector = options.returnFieldSelector || null;
this.returnFieldSelector = options.returnFieldSelector || null;
this.requestId = _requestId++;

@@ -88,17 +88,5 @@

var self = this;
// Basic length
var length = 4
+ Buffer.byteLength(self.ns)
+ 1 + 4 + 4
+ self.bson.calculateObjectSize(self.query, self.serializeFunctions, true)
+ (4 * 4);
var buffers = [];
var projection = null;
// Additional size for field selection
if(self.returnFieldSelector && Object.keys(self.returnFieldSelector).length > 0) {
length += self.bson.calculateObjectSize(self.returnFieldSelector, self.serializeFunctions, true);
}
// Allocate buffer for message
var _buffer = new Buffer(length);
// Set up the flags

@@ -117,94 +105,90 @@ var flags = 0;

// Initial index
// Allocate write protocol header buffer
var header = new Buffer(
4 * 4 // Header
+ 4 // Flags
+ Buffer.byteLength(self.ns) + 1 // namespace
+ 4 // numberToSkip
+ 4 // numberToReturn
);
// Add header to buffers
buffers.push(header);
// Serialize the query
var query = self.bson.serialize(this.query
, this.checkKeys
, true
, this.serializeFunctions)
// Add query document
buffers.push(query);
if(self.returnFieldSelector && Object.keys(self.returnFieldSelector).length > 0) {
// Serialize the projection document
projection = self.bson.serialize(this.returnFieldSelector, this.checkKeys, true, this.serializeFunctions);
// Add projection document
buffers.push(projection);
}
// Total message size
var totalLength = header.length + query.length + (projection ? projection.length : 0);
// Set up the index
var index = 4;
// Write total document length
header[3] = (totalLength >> 24) & 0xff;
header[2] = (totalLength >> 16) & 0xff;
header[1] = (totalLength >> 8) & 0xff;
header[0] = (totalLength) & 0xff;
// Write header information requestId
_buffer[index + 3] = (this.requestId >> 24) & 0xff;
_buffer[index + 2] = (this.requestId >> 16) & 0xff;
_buffer[index + 1] = (this.requestId >> 8) & 0xff;
_buffer[index] = (this.requestId) & 0xff;
header[index + 3] = (this.requestId >> 24) & 0xff;
header[index + 2] = (this.requestId >> 16) & 0xff;
header[index + 1] = (this.requestId >> 8) & 0xff;
header[index] = (this.requestId) & 0xff;
index = index + 4;
// Write header information responseTo
_buffer[index + 3] = (0 >> 24) & 0xff;
_buffer[index + 2] = (0 >> 16) & 0xff;
_buffer[index + 1] = (0 >> 8) & 0xff;
_buffer[index] = (0) & 0xff;
header[index + 3] = (0 >> 24) & 0xff;
header[index + 2] = (0 >> 16) & 0xff;
header[index + 1] = (0 >> 8) & 0xff;
header[index] = (0) & 0xff;
index = index + 4;
// Write header information OP_QUERY
_buffer[index + 3] = (OP_QUERY >> 24) & 0xff;
_buffer[index + 2] = (OP_QUERY >> 16) & 0xff;
_buffer[index + 1] = (OP_QUERY >> 8) & 0xff;
_buffer[index] = (OP_QUERY) & 0xff;
header[index + 3] = (OP_QUERY >> 24) & 0xff;
header[index + 2] = (OP_QUERY >> 16) & 0xff;
header[index + 1] = (OP_QUERY >> 8) & 0xff;
header[index] = (OP_QUERY) & 0xff;
index = index + 4;
// Write header information flags
_buffer[index + 3] = (flags >> 24) & 0xff;
_buffer[index + 2] = (flags >> 16) & 0xff;
_buffer[index + 1] = (flags >> 8) & 0xff;
_buffer[index] = (flags) & 0xff;
header[index + 3] = (flags >> 24) & 0xff;
header[index + 2] = (flags >> 16) & 0xff;
header[index + 1] = (flags >> 8) & 0xff;
header[index] = (flags) & 0xff;
index = index + 4;
// Write collection name
index = index + _buffer.write(this.ns, index, 'utf8') + 1;
_buffer[index - 1] = 0;
index = index + header.write(this.ns, index, 'utf8') + 1;
header[index - 1] = 0;
// Write header information flags numberToSkip
_buffer[index + 3] = (this.numberToSkip >> 24) & 0xff;
_buffer[index + 2] = (this.numberToSkip >> 16) & 0xff;
_buffer[index + 1] = (this.numberToSkip >> 8) & 0xff;
_buffer[index] = (this.numberToSkip) & 0xff;
header[index + 3] = (this.numberToSkip >> 24) & 0xff;
header[index + 2] = (this.numberToSkip >> 16) & 0xff;
header[index + 1] = (this.numberToSkip >> 8) & 0xff;
header[index] = (this.numberToSkip) & 0xff;
index = index + 4;
// Write header information flags numberToReturn
_buffer[index + 3] = (this.numberToReturn >> 24) & 0xff;
_buffer[index + 2] = (this.numberToReturn >> 16) & 0xff;
_buffer[index + 1] = (this.numberToReturn >> 8) & 0xff;
_buffer[index] = (this.numberToReturn) & 0xff;
header[index + 3] = (this.numberToReturn >> 24) & 0xff;
header[index + 2] = (this.numberToReturn >> 16) & 0xff;
header[index + 1] = (this.numberToReturn >> 8) & 0xff;
header[index] = (this.numberToReturn) & 0xff;
index = index + 4;
// Serialize query
var queryLength = this.bson.serializeWithBufferAndIndex(this.query
, this.checkKeys
, _buffer, index
, this.serializeFunctions) - index + 1;
// Write header information flags queryLength
_buffer[index + 3] = (queryLength >> 24) & 0xff;
_buffer[index + 2] = (queryLength >> 16) & 0xff;
_buffer[index + 1] = (queryLength >> 8) & 0xff;
_buffer[index] = (queryLength) & 0xff;
index = index + 4;
// Add to the index
index = index - 4 + queryLength;
_buffer[index + 1] = 0x00;
// If we have field selectors
if(this.returnFieldSelector && Object.keys(this.returnFieldSelector).length > 0) {
var fieldSelectorLength = this.bson.serializeWithBufferAndIndex(this.returnFieldSelector
, this.checkKeys
, _buffer
, index
, this.serializeFunctions) - index + 1;
// Write header information flags fieldSelectorLength
_buffer[index + 3] = (fieldSelectorLength >> 24) & 0xff;
_buffer[index + 2] = (fieldSelectorLength >> 16) & 0xff;
_buffer[index + 1] = (fieldSelectorLength >> 8) & 0xff;
_buffer[index] = (fieldSelectorLength) & 0xff;
index = index + 4;
index = index - 4 + fieldSelectorLength;
_buffer[index + 1] = 0x00;
}
// Write total document length
_buffer[3] = (index >> 24) & 0xff;
_buffer[2] = (index >> 16) & 0xff;
_buffer[1] = (index >> 8) & 0xff;
_buffer[0] = (index) & 0xff;
// Return buffer
return _buffer;
// Return the buffers
return buffers;
}

@@ -236,3 +220,3 @@

var _buffer = new Buffer(length);
// Write header information

@@ -404,7 +388,7 @@ // index = write32bit(index, _buffer, length);

this.index = this.index + 4;
// Fetch the request id for this reply
this.requestId = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24;
this.index = this.index + 4;
// Fetch the id of the request that triggered the response

@@ -416,7 +400,7 @@ this.responseTo = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24;

this.index = this.index + 4;
// Unpack flags
this.responseFlags = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24;
this.index = this.index + 4;
// Unpack the cursor

@@ -429,7 +413,7 @@ var lowBits = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24;

this.cursorId = new Long(lowBits, highBits);
// Unpack the starting from
this.startingFrom = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24;
this.index = this.index + 4;
// Unpack the number of objects returned

@@ -489,2 +473,2 @@ this.numberReturned = data[this.index] | data[this.index + 1] << 8 | data[this.index + 2] << 16 | data[this.index + 3] << 24;

, KillCursor: KillCursor
}
}

@@ -386,6 +386,11 @@ "use strict";

Connection.prototype.write = function(buffer) {
// console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ connection")
// console.log(Array.isArray(buffer))
// Debug log
if(this.logger.isDebug()) this.logger.debug(f('writing buffer [%s] to %s:%s', buffer.toString('hex'), this.host, this.port));
// Write out the command
this.connection.write(buffer, 'binary');
// this.connection.write(buffer, 'binary');
if(!Array.isArray(buffer)) return this.connection.write(buffer, 'binary');
// Iterate over all buffers and write them in order to the socket
for(var i = 0; i < buffer.length; i++) this.connection.write(buffer[i], 'binary');
}

@@ -392,0 +397,0 @@

@@ -6,3 +6,3 @@ "use strict";

, MongoError = require('./error')
, f = require('util').format;
, f = require('util').format;

@@ -20,3 +20,3 @@ /**

* allowing for iteration over the results returned from the underlying query.
*
*
* **CURSORS Cannot directly be instantiated**

@@ -27,3 +27,3 @@ * @example

* , assert = require('assert');
*
*
* var server = new Server({host: 'localhost', port: 27017});

@@ -33,3 +33,3 @@ * // Wait for the connection event

* assert.equal(null, err);
*
*
* // Execute the write

@@ -42,3 +42,3 @@ * var cursor = _server.cursor('integration_tests.inserts_example4', {

* });
*
*
* // Get the first document

@@ -50,3 +50,3 @@ * cursor.next(function(err, doc) {

* });
*
*
* // Start connecting

@@ -120,3 +120,3 @@ * server.connect();

//
//
// Did we pass in a cursor id

@@ -130,23 +130,23 @@ if(typeof cmd == 'number') {

Cursor.prototype.setCursorBatchSize = function(value) {
Cursor.prototype.setCursorBatchSize = function(value) {
this.cursorState.batchSize = value;
}
Cursor.prototype.cursorBatchSize = function() {
Cursor.prototype.cursorBatchSize = function() {
return this.cursorState.batchSize;
}
Cursor.prototype.setCursorLimit = function(value) {
Cursor.prototype.setCursorLimit = function(value) {
this.cursorState.limit = value;
}
Cursor.prototype.cursorLimit = function() {
Cursor.prototype.cursorLimit = function() {
return this.cursorState.limit;
}
Cursor.prototype.setCursorSkip = function(value) {
Cursor.prototype.setCursorSkip = function(value) {
this.cursorState.skip = value;
}
Cursor.prototype.cursorSkip = function() {
Cursor.prototype.cursorSkip = function() {
return this.cursorState.skip;

@@ -165,3 +165,3 @@ }

//
//
// Execute the first query

@@ -184,8 +184,8 @@ var execInitialQuery = function(self, query, cmd, options, cursorState, connection, logger, callbacks, callback) {

if(Array.isArray(result.documents) && result.documents.length == 1 && !cmd.find) {
if(result.documents[0]['$err']
if(result.documents[0]['$err']
|| result.documents[0]['errmsg']) {
return callback(MongoError.create(result.documents[0]), null);
return callback(MongoError.create(result.documents[0]), null);
}
if(result.documents[0].cursor != null
if(result.documents[0].cursor != null
&& typeof result.documents[0].cursor != 'string') {

@@ -212,3 +212,3 @@ var id = result.documents[0].cursor.id;

return callback(null, null);
}
}
}

@@ -257,3 +257,3 @@

* @return {Cursor}
*/
*/
Cursor.prototype.clone = function() {

@@ -308,4 +308,2 @@ return this.topology.cursor(this.ns, this.cmd, this.options);

var elements = this.cursorState.documents.slice(this.cursorState.cursorIndex, this.cursorState.cursorIndex + length);
this.cursorState.currentLimit = this.cursorState.currentLimit + length;
this.cursorState.cursorIndex = this.cursorState.cursorIndex + length;

@@ -320,2 +318,13 @@ // Transform the doc with passed in transformation method if provided

// Ensure we do not return any more documents than the limit imposed
// Just return the number of elements up to the limit
if(this.cursorState.limit > 0 && (this.cursorState.currentLimit + elements.length) > this.cursorState.limit) {
elements = elements.slice(0, (this.cursorState.limit - this.cursorState.currentLimit));
this.kill();
}
// Adjust current limit
this.cursorState.currentLimit = this.cursorState.currentLimit + elements.length;
this.cursorState.cursorIndex = this.cursorState.cursorIndex + elements.length;
// Return elements

@@ -351,3 +360,3 @@ return elements;

* @return {null}
*/
*/
Cursor.prototype.rewind = function() {

@@ -367,3 +376,3 @@ if(this.cursorState.init) {

this.cursorState.cursorIndex = 0;
}
}
}

@@ -375,3 +384,3 @@

var isConnectionDead = function(self, callback) {
if(self.connection
if(self.connection
&& !self.connection.isConnected()) {

@@ -401,3 +410,3 @@ self.cursorState.notified = true;

return true;
}
}

@@ -414,3 +423,3 @@ return false;

return true;
}
}

@@ -443,3 +452,3 @@ return false;

self.cursorState.cursorIndex = 0;
handleCallback(callback, null, null);
handleCallback(callback, null, null);
}

@@ -463,3 +472,3 @@

// Cursor is killed return null
if(isCursorKilled(self, callback)) return;
if(isCursorKilled(self, callback)) return;

@@ -523,3 +532,3 @@ // Cursor is dead but not marked killed, return null

}
}
}

@@ -552,3 +561,3 @@ // If we have exhaust

if(self.topology.isDestroyed()) return callback(new MongoError(f('connection destroyed, not possible to instantiate cursor')));
// query, cmd, options, cursorState, callback

@@ -564,3 +573,6 @@ execInitialQuery(self, self.query, self.cmd, self.options, self.cursorState, self.connection, self.logger, self.callbacks, function(err, r) {

} else if(self.cursorState.limit > 0 && self.cursorState.currentLimit >= self.cursorState.limit) {
return setCursorDeadAndNotified(self, callback);
// Ensure we kill the cursor on the server
self.kill();
// Set cursor in dead and notified state
return setCursorDeadAndNotified(self, callback);
} else if(self.cursorState.cursorIndex == self.cursorState.documents.length

@@ -583,3 +595,3 @@ && !Long.ZERO.equals(self.cursorState.cursorId)) {

if(self.cursorState.documents.length == 0 && Long.ZERO.equals(self.cursorState.cursorId)) self.cursorState.dead = true;
// Tailable cursor getMore result, notify owner about it

@@ -602,4 +614,4 @@ // No attempt is made here to retry, this is left to the user of the

});
} else if(self.cursorState.documents.length == self.cursorState.cursorIndex
&& self.cmd.tailable) {
} else if(self.cursorState.documents.length == self.cursorState.cursorIndex
&& self.cmd.tailable) {
return handleCallback(callback, MongoError.create({

@@ -610,3 +622,3 @@ message: "No more documents in tailed cursor"

}));
} else if(self.cursorState.documents.length == self.cursorState.cursorIndex
} else if(self.cursorState.documents.length == self.cursorState.cursorIndex
&& Long.ZERO.equals(self.cursorState.cursorId)) {

@@ -616,2 +628,5 @@ setCursorDeadAndNotified(self, callback);

if(self.cursorState.limit > 0 && self.cursorState.currentLimit >= self.cursorState.limit) {
// Ensure we kill the cursor on the server
self.kill();
// Set cursor in dead and notified state
return setCursorDeadAndNotified(self, callback);

@@ -633,3 +648,3 @@ }

handleCallback(callback, null, doc);
}
}
}

@@ -636,0 +651,0 @@

@@ -40,86 +40,88 @@ "use strict";

Insert.prototype.toBin = function() {
// Calculate total length of the document
var length = 4 + Buffer.byteLength(this.ns) + 1 + (4 * 4);
// Contains all the buffers to be written
var buffers = [];
// Calculate the size of all documents
// Header buffer
var header = new Buffer(
4 * 4 // Header
+ 4 // Flags
+ Buffer.byteLength(this.ns) + 1 // namespace
);
// Add header to buffers
buffers.push(header);
// Total length of the message
var totalLength = header.length;
// Serialize all the documents
for(var i = 0; i < this.documents.length; i++) {
var docsize = this.bson.calculateObjectSize(this.documents[i], this.serializeFunctions, true);
var buffer = this.bson.serialize(this.documents[i]
, this.checkKeys
, true
, this.serializeFunctions);
// Document is larger than maxBsonObjectSize, terminate serialization
if(docsize > this.ismaster.maxBsonObjectSize) {
throw new MongoError("Document exceeds maximum allowed bson size of " + this.ismaster.maxBsonObjectSize + " bytes");
if(buffer.length > this.ismaster.maxBsonObjectSize) {
throw new MongoError("Document exceeds maximum allowed bson size of " + this.ismaster.maxBsonObjectSize + " bytes");
}
// Add to total command size
length += docsize;
// Add to total length of wire protocol message
totalLength = totalLength + buffer.length;
// Add to buffer
buffers.push(buffer);
}
// Command is larger than maxMessageSizeBytes terminate serialization
if(length > this.ismaster.maxBsonObjectSize) {
if(totalLength > this.ismaster.maxMessageSizeBytes) {
throw new MongoError("Command exceeds maximum message size of " + this.ismaster.maxMessageSizeBytes + " bytes");
}
// Create command buffer
var buffer = new Buffer(length);
// Add all the metadata
var index = 0;
// Write header length
buffer[index + 3] = (length >> 24) & 0xff;
buffer[index + 2] = (length >> 16) & 0xff;
buffer[index + 1] = (length >> 8) & 0xff;
buffer[index] = (length) & 0xff;
header[index + 3] = (totalLength >> 24) & 0xff;
header[index + 2] = (totalLength >> 16) & 0xff;
header[index + 1] = (totalLength >> 8) & 0xff;
header[index] = (totalLength) & 0xff;
index = index + 4;
// Write header requestId
buffer[index + 3] = (this.requestId >> 24) & 0xff;
buffer[index + 2] = (this.requestId >> 16) & 0xff;
buffer[index + 1] = (this.requestId >> 8) & 0xff;
buffer[index] = (this.requestId) & 0xff;
header[index + 3] = (this.requestId >> 24) & 0xff;
header[index + 2] = (this.requestId >> 16) & 0xff;
header[index + 1] = (this.requestId >> 8) & 0xff;
header[index] = (this.requestId) & 0xff;
index = index + 4;
// No flags
buffer[index + 3] = (0 >> 24) & 0xff;
buffer[index + 2] = (0 >> 16) & 0xff;
buffer[index + 1] = (0 >> 8) & 0xff;
buffer[index] = (0) & 0xff;
header[index + 3] = (0 >> 24) & 0xff;
header[index + 2] = (0 >> 16) & 0xff;
header[index + 1] = (0 >> 8) & 0xff;
header[index] = (0) & 0xff;
index = index + 4;
// Operation
buffer[index + 3] = (OP_INSERT >> 24) & 0xff;
buffer[index + 2] = (OP_INSERT >> 16) & 0xff;
buffer[index + 1] = (OP_INSERT >> 8) & 0xff;
buffer[index] = (OP_INSERT) & 0xff;
header[index + 3] = (OP_INSERT >> 24) & 0xff;
header[index + 2] = (OP_INSERT >> 16) & 0xff;
header[index + 1] = (OP_INSERT >> 8) & 0xff;
header[index] = (OP_INSERT) & 0xff;
index = index + 4;
// Flags
buffer[index + 3] = (this.flags >> 24) & 0xff;
buffer[index + 2] = (this.flags >> 16) & 0xff;
buffer[index + 1] = (this.flags >> 8) & 0xff;
buffer[index] = (this.flags) & 0xff;
header[index + 3] = (this.flags >> 24) & 0xff;
header[index + 2] = (this.flags >> 16) & 0xff;
header[index + 1] = (this.flags >> 8) & 0xff;
header[index] = (this.flags) & 0xff;
index = index + 4;
// Write collection name
index = index + buffer.write(this.ns, index, 'utf8') + 1;
buffer[index - 1] = 0;
index = index + header.write(this.ns, index, 'utf8') + 1;
header[index - 1] = 0;
// Write all the bson documents to the buffer at the index offset
for(var i = 0; i < this.documents.length; i++) {
// Serialize the entry
var newIndex = this.bson.serializeWithBufferAndIndex(this.documents[i], this.checkKeys, buffer, index, this.serializeFunctions);
var docSize = newIndex - index + 1;
// Write the doc size
buffer[index + 3] = (docSize >> 24) & 0xff;
buffer[index + 2] = (docSize >> 16) & 0xff;
buffer[index + 1] = (docSize >> 8) & 0xff;
buffer[index] = (docSize) & 0xff;
// Adjust index
index = index + docSize;
// Add terminating 0 for the object
buffer[index - 1] = 0;
}
return buffer;
// Return the buffers
return buffers;
}
var Update = function(requestId, ismaster, bson, ns, update, options) {
var Update = function(requestId, ismaster, bson, ns, update, options) {
// Basic options needed to be passed in

@@ -154,84 +156,89 @@ if(ns == null) throw new MongoError("ns must be specified for query");

Update.prototype.toBin = function() {
// Calculate total length of the document
var length = (4 * 4) + 4 + Buffer.byteLength(this.ns) + 1 + 4;
// Contains all the buffers to be written
var buffers = [];
// Calculate the two object sizes
var qSize = this.bson.calculateObjectSize(this.q, this.serializeFunctions, true);
var uSize = this.bson.calculateObjectSize(this.u, this.serializeFunctions, true);
// Header buffer
var header = new Buffer(
4 * 4 // Header
+ 4 // ZERO
+ Buffer.byteLength(this.ns) + 1 // namespace
+ 4 // Flags
);
// Update the length
length = length + qSize + uSize;
// Create command buffer
var buffer = new Buffer(length);
// Add header to buffers
buffers.push(header);
// Total length of the message
var totalLength = header.length;
// Serialize the selector
var selector = this.bson.serialize(this.q
, this.checkKeys
, true
, this.serializeFunctions);
buffers.push(selector);
totalLength = totalLength + selector.length;
// Serialize the update
var update = this.bson.serialize(this.u
, this.checkKeys
, true
, this.serializeFunctions);
buffers.push(update);
totalLength = totalLength + update.length;
// Index in header buffer
var index = 0;
// Write header length
buffer[index + 3] = (length >> 24) & 0xff;
buffer[index + 2] = (length >> 16) & 0xff;
buffer[index + 1] = (length >> 8) & 0xff;
buffer[index] = (length) & 0xff;
header[index + 3] = (totalLength >> 24) & 0xff;
header[index + 2] = (totalLength >> 16) & 0xff;
header[index + 1] = (totalLength >> 8) & 0xff;
header[index] = (totalLength) & 0xff;
index = index + 4;
// Write header requestId
buffer[index + 3] = (this.requestId >> 24) & 0xff;
buffer[index + 2] = (this.requestId >> 16) & 0xff;
buffer[index + 1] = (this.requestId >> 8) & 0xff;
buffer[index] = (this.requestId) & 0xff;
header[index + 3] = (this.requestId >> 24) & 0xff;
header[index + 2] = (this.requestId >> 16) & 0xff;
header[index + 1] = (this.requestId >> 8) & 0xff;
header[index] = (this.requestId) & 0xff;
index = index + 4;
// No flags
buffer[index + 3] = (0 >> 24) & 0xff;
buffer[index + 2] = (0 >> 16) & 0xff;
buffer[index + 1] = (0 >> 8) & 0xff;
buffer[index] = (0) & 0xff;
header[index + 3] = (0 >> 24) & 0xff;
header[index + 2] = (0 >> 16) & 0xff;
header[index + 1] = (0 >> 8) & 0xff;
header[index] = (0) & 0xff;
index = index + 4;
// Operation
buffer[index + 3] = (OP_UPDATE >> 24) & 0xff;
buffer[index + 2] = (OP_UPDATE >> 16) & 0xff;
buffer[index + 1] = (OP_UPDATE >> 8) & 0xff;
buffer[index] = (OP_UPDATE) & 0xff;
header[index + 3] = (OP_UPDATE >> 24) & 0xff;
header[index + 2] = (OP_UPDATE >> 16) & 0xff;
header[index + 1] = (OP_UPDATE >> 8) & 0xff;
header[index] = (OP_UPDATE) & 0xff;
index = index + 4;
// Write ZERO
buffer[index + 3] = (0 >> 24) & 0xff;
buffer[index + 2] = (0 >> 16) & 0xff;
buffer[index + 1] = (0 >> 8) & 0xff;
buffer[index] = (0) & 0xff;
header[index + 3] = (0 >> 24) & 0xff;
header[index + 2] = (0 >> 16) & 0xff;
header[index + 1] = (0 >> 8) & 0xff;
header[index] = (0) & 0xff;
index = index + 4;
// Write collection name
index = index + buffer.write(this.ns, index, 'utf8') + 1;
buffer[index - 1] = 0;
index = index + header.write(this.ns, index, 'utf8') + 1;
header[index - 1] = 0;
// Flags
buffer[index + 3] = (this.flags >> 24) & 0xff;
buffer[index + 2] = (this.flags >> 16) & 0xff;
buffer[index + 1] = (this.flags >> 8) & 0xff;
buffer[index] = (this.flags) & 0xff;
header[index + 3] = (this.flags >> 24) & 0xff;
header[index + 2] = (this.flags >> 16) & 0xff;
header[index + 1] = (this.flags >> 8) & 0xff;
header[index] = (this.flags) & 0xff;
index = index + 4;
// Serialize the selector
var length = this.bson.serializeWithBufferAndIndex(this.q, this.checkKeys, buffer, index, this.serializeFunctions) - index + 1;
buffer[index + 3] = (length >> 24) & 0xff;
buffer[index + 2] = (length >> 16) & 0xff;
buffer[index + 1] = (length >> 8) & 0xff;
buffer[index] = (length) & 0xff;
index = index + length;
// Serialize the update statement
length = this.bson.serializeWithBufferAndIndex(this.u, false, buffer, index, this.serializeFunctions) - index + 1;
buffer[index + 3] = (length >> 24) & 0xff;
buffer[index + 2] = (length >> 16) & 0xff;
buffer[index + 1] = (length >> 8) & 0xff;
buffer[index] = (length) & 0xff;
index = index + length;
// Return the buffer
return buffer;
// Return the buffers
return buffers;
}
var Remove = function(requestId, ismaster, bson, ns, remove, options) {
var Remove = function(requestId, ismaster, bson, ns, remove, options) {
// Basic options needed to be passed in

@@ -263,70 +270,78 @@ if(ns == null) throw new MongoError("ns must be specified for query");

Remove.prototype.toBin = function() {
// Calculate total length of the document
var length = (4 * 4) + 4 + Buffer.byteLength(this.ns) + 1 + 4;
// Contains all the buffers to be written
var buffers = [];
// Calculate the two object sizes
var qSize = this.bson.calculateObjectSize(this.q, this.serializeFunctions, true);
// Header buffer
var header = new Buffer(
4 * 4 // Header
+ 4 // ZERO
+ Buffer.byteLength(this.ns) + 1 // namespace
+ 4 // Flags
);
// Update the length
length = length + qSize;
// Create command buffer
var buffer = new Buffer(length);
// Add header to buffers
buffers.push(header);
// Total length of the message
var totalLength = header.length;
// Serialize the selector
var selector = this.bson.serialize(this.q
, this.checkKeys
, true
, this.serializeFunctions);
buffers.push(selector);
totalLength = totalLength + selector.length;
// Index in header buffer
var index = 0;
// Write header length
buffer[index + 3] = (length >> 24) & 0xff;
buffer[index + 2] = (length >> 16) & 0xff;
buffer[index + 1] = (length >> 8) & 0xff;
buffer[index] = (length) & 0xff;
header[index + 3] = (totalLength >> 24) & 0xff;
header[index + 2] = (totalLength >> 16) & 0xff;
header[index + 1] = (totalLength >> 8) & 0xff;
header[index] = (totalLength) & 0xff;
index = index + 4;
// Write header requestId
buffer[index + 3] = (this.requestId >> 24) & 0xff;
buffer[index + 2] = (this.requestId >> 16) & 0xff;
buffer[index + 1] = (this.requestId >> 8) & 0xff;
buffer[index] = (this.requestId) & 0xff;
header[index + 3] = (this.requestId >> 24) & 0xff;
header[index + 2] = (this.requestId >> 16) & 0xff;
header[index + 1] = (this.requestId >> 8) & 0xff;
header[index] = (this.requestId) & 0xff;
index = index + 4;
// No flags
buffer[index + 3] = (0 >> 24) & 0xff;
buffer[index + 2] = (0 >> 16) & 0xff;
buffer[index + 1] = (0 >> 8) & 0xff;
buffer[index] = (0) & 0xff;
header[index + 3] = (0 >> 24) & 0xff;
header[index + 2] = (0 >> 16) & 0xff;
header[index + 1] = (0 >> 8) & 0xff;
header[index] = (0) & 0xff;
index = index + 4;
// Operation
buffer[index + 3] = (OP_DELETE >> 24) & 0xff;
buffer[index + 2] = (OP_DELETE >> 16) & 0xff;
buffer[index + 1] = (OP_DELETE >> 8) & 0xff;
buffer[index] = (OP_DELETE) & 0xff;
header[index + 3] = (OP_DELETE >> 24) & 0xff;
header[index + 2] = (OP_DELETE >> 16) & 0xff;
header[index + 1] = (OP_DELETE >> 8) & 0xff;
header[index] = (OP_DELETE) & 0xff;
index = index + 4;
// Write ZERO
buffer[index + 3] = (0 >> 24) & 0xff;
buffer[index + 2] = (0 >> 16) & 0xff;
buffer[index + 1] = (0 >> 8) & 0xff;
buffer[index] = (0) & 0xff;
header[index + 3] = (0 >> 24) & 0xff;
header[index + 2] = (0 >> 16) & 0xff;
header[index + 1] = (0 >> 8) & 0xff;
header[index] = (0) & 0xff;
index = index + 4;
// Write collection name
index = index + buffer.write(this.ns, index, 'utf8') + 1;
buffer[index - 1] = 0;
index = index + header.write(this.ns, index, 'utf8') + 1;
header[index - 1] = 0;
// Write ZERO
buffer[index + 3] = (this.flags >> 24) & 0xff;
buffer[index + 2] = (this.flags >> 16) & 0xff;
buffer[index + 1] = (this.flags >> 8) & 0xff;
buffer[index] = (this.flags) & 0xff;
header[index + 3] = (this.flags >> 24) & 0xff;
header[index + 2] = (this.flags >> 16) & 0xff;
header[index + 1] = (this.flags >> 8) & 0xff;
header[index] = (this.flags) & 0xff;
index = index + 4;
// Serialize the selector
var length = this.bson.serializeWithBufferAndIndex(this.q, this.checkKeys, buffer, index, this.serializeFunctions) - index + 1;
buffer[index + 3] = (length >> 24) & 0xff;
buffer[index + 2] = (length >> 16) & 0xff;
buffer[index + 1] = (length >> 8) & 0xff;
buffer[index] = (length) & 0xff;
index = index + length;
// Return the buffer
return buffer;
// Return the buffers
return buffers;
}

@@ -338,2 +353,2 @@

, Remove: Remove
}
}
{
"name": "mongodb-core",
"version": "1.1.33",
"version": "1.2.0",
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications",

@@ -18,3 +18,3 @@ "main": "index.js",

"dependencies": {
"bson": "~0.3"
"bson": "~0.4"
},

@@ -21,0 +21,0 @@ "devDependencies": {

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