Skip to content

Commit 0073dd2

Browse files
committed
NODE-540 implemented bypassDocumentValidation
1 parent 78bba8f commit 0073dd2

File tree

7 files changed

+552
-4
lines changed

7 files changed

+552
-4
lines changed

lib/bulk/ordered.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ function OrderedBulkOperation(topology, collection, options) {
286286
, promiseLibrary: promiseLibrary
287287
// Fundamental error
288288
, err: null
289+
// Bypass validation
290+
, bypassDocumentValidation: typeof options.bypassDocumentValidation == 'boolean' ? options.bypassDocumentValidation : false
289291
}
290292
}
291293

@@ -434,6 +436,11 @@ var executeCommands = function(self, callback) {
434436
finalOptions.serializeFunctions = true
435437
}
436438

439+
// Is the bypassDocumentValidation options specific
440+
if(self.s.bypassDocumentValidation == true) {
441+
finalOptions.bypassDocumentValidation = true;
442+
}
443+
437444
try {
438445
if(batch.batchType == common.INSERT) {
439446
self.s.topology.insert(self.s.collection.namespace, batch.operations, finalOptions, resultHandler);

lib/bulk/unordered.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ var UnorderedBulkOperation = function(topology, collection, options) {
295295
, collection: collection
296296
// Promise Library
297297
, promiseLibrary: promiseLibrary
298+
// Bypass validation
299+
, bypassDocumentValidation: typeof options.bypassDocumentValidation == 'boolean' ? options.bypassDocumentValidation : false
298300
}
299301
}
300302

@@ -422,6 +424,11 @@ var executeBatch = function(self, batch, callback) {
422424
finalOptions.serializeFunctions = true
423425
}
424426

427+
// Is the bypassDocumentValidation options specific
428+
if(self.s.bypassDocumentValidation == true) {
429+
finalOptions.bypassDocumentValidation = true;
430+
}
431+
425432
try {
426433
if(batch.batchType == common.INSERT) {
427434
self.s.topology.insert(self.s.collection.namespace, batch.operations, finalOptions, resultHandler);

lib/collection.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ define.classMethod('find', {callback: false, promise:false, returns: [Cursor]});
355355
* @param {boolean} [options.j=false] Specify a journal write concern.
356356
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
357357
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
358+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
358359
* @param {Collection~insertWriteOpCallback} [callback] The command result callback
359360
* @return {Promise} returns Promise if no callback passed
360361
*/
@@ -511,6 +512,7 @@ define.classMethod('insertMany', {callback: true, promise:true});
511512
* @param {boolean} [options.j=false] Specify a journal write concern.
512513
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
513514
* @param {boolean} [options.ordered=true] Execute write operation in ordered or unordered fashion.
515+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
514516
* @param {Collection~bulkWriteOpCallback} [callback] The command result callback
515517
* @return {Promise} returns Promise if no callback passed
516518
*/
@@ -680,6 +682,7 @@ define.classMethod('bulkWrite', {callback: true, promise:true});
680682
* @param {boolean} [options.j=false] Specify a journal write concern.
681683
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
682684
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
685+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
683686
* @param {Collection~insertWriteOpCallback} [callback] The command result callback
684687
* @return {Promise} returns Promise if no callback passed
685688
* @deprecated Use insertOne, insertMany or bulkWrite
@@ -730,6 +733,7 @@ define.classMethod('insert', {callback: true, promise:true});
730733
* @param {(number|string)} [options.w=null] The write concern.
731734
* @param {number} [options.wtimeout=null] The write concern timeout.
732735
* @param {boolean} [options.j=false] Specify a journal write concern.
736+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
733737
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
734738
* @return {Promise} returns Promise if no callback passed
735739
*/
@@ -778,6 +782,7 @@ define.classMethod('updateOne', {callback: true, promise:true});
778782
* @param {(number|string)} [options.w=null] The write concern.
779783
* @param {number} [options.wtimeout=null] The write concern timeout.
780784
* @param {boolean} [options.j=false] Specify a journal write concern.
785+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
781786
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
782787
* @return {Promise} returns Promise if no callback passed
783788
*/
@@ -910,6 +915,7 @@ var updateDocuments = function(self, selector, document, options, callback) {
910915
* @param {boolean} [options.j=false] Specify a journal write concern.
911916
* @param {boolean} [options.upsert=false] Update operation is an upsert.
912917
* @param {boolean} [options.multi=false] Update one/all documents with operation.
918+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
913919
* @param {Collection~writeOpCallback} [callback] The command result callback
914920
* @throws {MongoError}
915921
* @return {Promise} returns Promise if no callback passed
@@ -955,6 +961,7 @@ define.classMethod('update', {callback: true, promise:true});
955961
* @param {(number|string)} [options.w=null] The write concern.
956962
* @param {number} [options.wtimeout=null] The write concern timeout.
957963
* @param {boolean} [options.j=false] Specify a journal write concern.
964+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
958965
* @param {Collection~deleteWriteOpCallback} [callback] The command result callback
959966
* @return {Promise} returns Promise if no callback passed
960967
*/
@@ -2194,6 +2201,11 @@ var findAndModify = function(self, query, sort, doc, options, callback) {
21942201
queryObject.writeConcern = finalOptions.writeConcern;
21952202
}
21962203

2204+
// Have we specified bypassDocumentValidation
2205+
if(typeof finalOptions.bypassDocumentValidation == 'boolean') {
2206+
queryObject.bypassDocumentValidation = finalOptions.bypassDocumentValidation;
2207+
}
2208+
21972209
// Execute the command
21982210
self.s.db.command(queryObject
21992211
, options, function(err, result) {
@@ -2257,6 +2269,7 @@ define.classMethod('findAndRemove', {callback: true, promise:true});
22572269
* @param {boolean} [options.explain=false] Explain returns the aggregation execution plan (requires mongodb 2.6 >).
22582270
* @param {boolean} [options.allowDiskUse=false] allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 >).
22592271
* @param {number} [options.maxTimeMS=null] maxTimeMS specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point.
2272+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
22602273
* @param {Collection~resultCallback} callback The command result callback
22612274
* @return {(null|AggregationCursor)}
22622275
*/
@@ -2296,6 +2309,12 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
22962309

22972310
// Build the command
22982311
var command = { aggregate : this.s.name, pipeline : pipeline};
2312+
2313+
// If we have bypassDocumentValidation set
2314+
if(typeof options.bypassDocumentValidation == 'boolean') {
2315+
command.bypassDocumentValidation = options.bypassDocumentValidation;
2316+
}
2317+
22992318
// If we have allowDiskUse defined
23002319
if(options.allowDiskUse) command.allowDiskUse = options.allowDiskUse;
23012320
if(typeof options.maxTimeMS == 'number') command.maxTimeMS = options.maxTimeMS;
@@ -2764,6 +2783,7 @@ function processScope (scope) {
27642783
* @param {object} [options.scope=null] Can pass in variables that can be access from map/reduce/finalize.
27652784
* @param {boolean} [options.jsMode=false] It is possible to make the execution stay in JS. Provided in MongoDB > 2.0.X.
27662785
* @param {boolean} [options.verbose=false] Provide statistics on job execution time.
2786+
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
27672787
* @param {Collection~resultCallback} [callback] The command result callback
27682788
* @throws {MongoError}
27692789
* @return {Promise} returns Promise if no callback passed
@@ -2826,6 +2846,11 @@ var mapReduce = function(self, map, reduce, options, callback) {
28262846
options.readPreference = 'primary';
28272847
}
28282848

2849+
// Is bypassDocumentValidation specified
2850+
if(typeof options.bypassDocumentValidation == 'boolean') {
2851+
mapCommandHash.bypassDocumentValidation = options.bypassDocumentValidation;
2852+
}
2853+
28292854
// Execute command
28302855
self.s.db.command(mapCommandHash, {readPreference:options.readPreference}, function (err, result) {
28312856
if(err) return handleCallback(callback, err);

0 commit comments

Comments
 (0)