Page MenuHomeSealhub

bin_node_modules_mongodb_lib_mongodb_commands_update_command.js.html
No OneTemporary

bin_node_modules_mongodb_lib_mongodb_commands_update_command.js.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bin/node_modules/mongodb/lib/mongodb/commands/update_command.js - Prometheus Framework</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><img src="../assets/css/logo.png" title="Prometheus Framework"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 0.1</em>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/Represents a
Replicaset Configuration.html">Represents a
Replicaset Configuration</a></li>
<li><a href="../classes/Represents a BatchWriteResult.html">Represents a BatchWriteResult</a></li>
<li><a href="../classes/Represents a Collection.html">Represents a Collection</a></li>
<li><a href="../classes/Represents a Cursor..html">Represents a Cursor.</a></li>
<li><a href="../classes/Represents a CursorStream..html">Represents a CursorStream.</a></li>
<li><a href="../classes/Represents a Db.html">Represents a Db</a></li>
<li><a href="../classes/Represents a GridFS File Stream..html">Represents a GridFS File Stream.</a></li>
<li><a href="../classes/.html"></a></li>
<li><a href="../classes/Represents a MongoClient.html">Represents a MongoClient</a></li>
<li><a href="../classes/Represents a Mongos connection with failover to backup proxies.html">Represents a Mongos connection with failover to backup proxies</a></li>
<li><a href="../classes/Represents a OrderedBulkOperation.html">Represents a OrderedBulkOperation</a></li>
<li><a href="../classes/Represents a Read Preference..html">Represents a Read Preference.</a></li>
<li><a href="../classes/Represents a Server connection..html">Represents a Server connection.</a></li>
<li><a href="../classes/Represents a UnorderedBulkOperation.html">Represents a UnorderedBulkOperation</a></li>
<li><a href="../classes/Represents the Admin methods of MongoDB..html">Represents the Admin methods of MongoDB.</a></li>
<li><a href="../classes/Represents the Grid..html">Represents the Grid.</a></li>
<li><a href="../classes/Represents the GridStore..html">Represents the GridStore.</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/association.html">association</a></li>
<li><a href="../modules/database-accessor.html">database-accessor</a></li>
<li><a href="../modules/field-type-manager.html">field-type-manager</a></li>
<li><a href="../modules/resource-type-manager.html">resource-type-manager</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
<label for="api-show-deprecated">
<input type="checkbox" id="api-show-deprecated">
Deprecated
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1 class="file-heading">File: bin/node_modules/mongodb/lib/mongodb/commands/update_command.js</h1>
<div class="file">
<pre class="code prettyprint linenums">
var BaseCommand = require(&#x27;./base_command&#x27;).BaseCommand,
inherits = require(&#x27;util&#x27;).inherits;
/**
Update Document Command
**/
var UpdateCommand = exports.UpdateCommand = function(db, collectionName, spec, document, options) {
BaseCommand.call(this);
var object = spec;
if(Buffer.isBuffer(object)) {
var object_size = object[0] | object[1] &lt;&lt; 8 | object[2] &lt;&lt; 16 | object[3] &lt;&lt; 24;
if(object_size != object.length) {
var error = new Error(&quot;update spec raw message size does not match message header size [&quot; + object.length + &quot;] != [&quot; + object_size + &quot;]&quot;);
error.name = &#x27;MongoError&#x27;;
throw error;
}
}
var object = document;
if(Buffer.isBuffer(object)) {
var object_size = object[0] | object[1] &lt;&lt; 8 | object[2] &lt;&lt; 16 | object[3] &lt;&lt; 24;
if(object_size != object.length) {
var error = new Error(&quot;update document raw message size does not match message header size [&quot; + object.length + &quot;] != [&quot; + object_size + &quot;]&quot;);
error.name = &#x27;MongoError&#x27;;
throw error;
}
}
this.collectionName = collectionName;
this.spec = spec;
this.document = document;
this.db = db;
this.serializeFunctions = false;
this.checkKeys = typeof options.checkKeys != &#x27;boolean&#x27; ? false : options.checkKeys;
// Generate correct flags
var db_upsert = 0;
var db_multi_update = 0;
db_upsert = options != null &amp;&amp; options[&#x27;upsert&#x27;] != null ? (options[&#x27;upsert&#x27;] == true ? 1 : 0) : db_upsert;
db_multi_update = options != null &amp;&amp; options[&#x27;multi&#x27;] != null ? (options[&#x27;multi&#x27;] == true ? 1 : 0) : db_multi_update;
// Flags
this.flags = parseInt(db_multi_update.toString() + db_upsert.toString(), 2);
// Let us defined on a command basis if we want functions to be serialized or not
if(options[&#x27;serializeFunctions&#x27;] != null &amp;&amp; options[&#x27;serializeFunctions&#x27;]) {
this.serializeFunctions = true;
}
};
inherits(UpdateCommand, BaseCommand);
UpdateCommand.OP_UPDATE = 2001;
/*
struct {
MsgHeader header; // standard message header
int32 ZERO; // 0 - reserved for future use
cstring fullCollectionName; // &quot;dbname.collectionname&quot;
int32 flags; // bit vector. see below
BSON spec; // the query to select the document
BSON document; // the document data to update with or insert
}
*/
UpdateCommand.prototype.toBinary = function(bsonSettings) {
// Validate that we are not passing 0x00 in the colletion name
if(!!~this.collectionName.indexOf(&quot;\x00&quot;)) {
throw new Error(&quot;namespace cannot contain a null character&quot;);
}
// Calculate total length of the document
var totalLengthOfCommand = 4 + Buffer.byteLength(this.collectionName) + 1 + 4 + this.db.bson.calculateObjectSize(this.spec, false, true) +
this.db.bson.calculateObjectSize(this.document, this.serializeFunctions, true) + (4 * 4);
// Enforce maximum bson size
if(!bsonSettings.disableDriverBSONSizeCheck
&amp;&amp; totalLengthOfCommand &gt; bsonSettings.maxBsonSize)
throw new Error(&quot;Document exceeds maximum allowed bson size of &quot; + bsonSettings.maxBsonSize + &quot; bytes&quot;);
if(bsonSettings.disableDriverBSONSizeCheck
&amp;&amp; totalLengthOfCommand &gt; bsonSettings.maxMessageSizeBytes)
throw new Error(&quot;Command exceeds maximum message size of &quot; + bsonSettings.maxMessageSizeBytes + &quot; bytes&quot;);
// Let&#x27;s build the single pass buffer command
var _index = 0;
var _command = new Buffer(totalLengthOfCommand);
// Write the header information to the buffer
_command[_index + 3] = (totalLengthOfCommand &gt;&gt; 24) &amp; 0xff;
_command[_index + 2] = (totalLengthOfCommand &gt;&gt; 16) &amp; 0xff;
_command[_index + 1] = (totalLengthOfCommand &gt;&gt; 8) &amp; 0xff;
_command[_index] = totalLengthOfCommand &amp; 0xff;
// Adjust index
_index = _index + 4;
// Write the request ID
_command[_index + 3] = (this.requestId &gt;&gt; 24) &amp; 0xff;
_command[_index + 2] = (this.requestId &gt;&gt; 16) &amp; 0xff;
_command[_index + 1] = (this.requestId &gt;&gt; 8) &amp; 0xff;
_command[_index] = this.requestId &amp; 0xff;
// Adjust index
_index = _index + 4;
// Write zero
_command[_index++] = 0;
_command[_index++] = 0;
_command[_index++] = 0;
_command[_index++] = 0;
// Write the op_code for the command
_command[_index + 3] = (UpdateCommand.OP_UPDATE &gt;&gt; 24) &amp; 0xff;
_command[_index + 2] = (UpdateCommand.OP_UPDATE &gt;&gt; 16) &amp; 0xff;
_command[_index + 1] = (UpdateCommand.OP_UPDATE &gt;&gt; 8) &amp; 0xff;
_command[_index] = UpdateCommand.OP_UPDATE &amp; 0xff;
// Adjust index
_index = _index + 4;
// Write zero
_command[_index++] = 0;
_command[_index++] = 0;
_command[_index++] = 0;
_command[_index++] = 0;
// Write the collection name to the command
_index = _index + _command.write(this.collectionName, _index, &#x27;utf8&#x27;) + 1;
_command[_index - 1] = 0;
// Write the update flags
_command[_index + 3] = (this.flags &gt;&gt; 24) &amp; 0xff;
_command[_index + 2] = (this.flags &gt;&gt; 16) &amp; 0xff;
_command[_index + 1] = (this.flags &gt;&gt; 8) &amp; 0xff;
_command[_index] = this.flags &amp; 0xff;
// Adjust index
_index = _index + 4;
// Document binary length
var documentLength = 0
var object = this.spec;
// Serialize the selector
// If we are passing a raw buffer, do minimal validation
if(Buffer.isBuffer(object)) {
var object_size = object[0] | object[1] &lt;&lt; 8 | object[2] &lt;&lt; 16 | object[3] &lt;&lt; 24;
if(object_size != object.length) throw new Error(&quot;raw message size does not match message header size [&quot; + object.length + &quot;] != [&quot; + object_size + &quot;]&quot;);
documentLength = object.length;
// Copy the data into the current buffer
object.copy(_command, _index);
} else {
documentLength = this.db.bson.serializeWithBufferAndIndex(object, this.checkKeys, _command, _index, false) - _index + 1;
}
// Write the length to the document
_command[_index + 3] = (documentLength &gt;&gt; 24) &amp; 0xff;
_command[_index + 2] = (documentLength &gt;&gt; 16) &amp; 0xff;
_command[_index + 1] = (documentLength &gt;&gt; 8) &amp; 0xff;
_command[_index] = documentLength &amp; 0xff;
// Update index in buffer
_index = _index + documentLength;
// Add terminating 0 for the object
_command[_index - 1] = 0;
// Document binary length
var documentLength = 0
var object = this.document;
// Serialize the document
// If we are passing a raw buffer, do minimal validation
if(Buffer.isBuffer(object)) {
var object_size = object[0] | object[1] &lt;&lt; 8 | object[2] &lt;&lt; 16 | object[3] &lt;&lt; 24;
if(object_size != object.length) throw new Error(&quot;raw message size does not match message header size [&quot; + object.length + &quot;] != [&quot; + object_size + &quot;]&quot;);
documentLength = object.length;
// Copy the data into the current buffer
object.copy(_command, _index);
} else {
documentLength = this.db.bson.serializeWithBufferAndIndex(object, false, _command, _index, this.serializeFunctions) - _index + 1;
}
// Write the length to the document
_command[_index + 3] = (documentLength &gt;&gt; 24) &amp; 0xff;
_command[_index + 2] = (documentLength &gt;&gt; 16) &amp; 0xff;
_command[_index + 1] = (documentLength &gt;&gt; 8) &amp; 0xff;
_command[_index] = documentLength &amp; 0xff;
// Update index in buffer
_index = _index + documentLength;
// Add terminating 0 for the object
_command[_index - 1] = 0;
return _command;
};
// Constants
UpdateCommand.DB_UPSERT = 0;
UpdateCommand.DB_MULTI_UPDATE = 1;
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>

File Metadata

Mime Type
text/html
Expires
Wed, Aug 13, 18:06 (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
876804
Default Alt Text
bin_node_modules_mongodb_lib_mongodb_commands_update_command.js.html (18 KB)

Event Timeline