@@ -293,7 +293,7 @@ var define = OrderedBulkOperation.define = new Define('OrderedBulkOperation', Or
293293
294294OrderedBulkOperation . prototype . raw = function ( op ) {
295295 var key = Object . keys ( op ) [ 0 ] ;
296-
296+ var forceServerObjectId = this . s . collection . s . db . options . forceServerObjectId ;
297297 // Update operations
298298 if ( ( op . updateOne && op . updateOne . q )
299299 || ( op . updateMany && op . updateMany . q )
@@ -325,16 +325,16 @@ OrderedBulkOperation.prototype.raw = function(op) {
325325
326326 // Insert operations
327327 if ( op . insertOne && op . insertOne . document == null ) {
328- if ( op . insertOne . _id == null ) op . insertOne . _id = new ObjectID ( ) ;
328+ if ( forceServerObjectId !== true && op . insertOne . _id == null ) op . insertOne . _id = new ObjectID ( ) ;
329329 return addToOperationsList ( this , common . INSERT , op . insertOne ) ;
330330 } else if ( op . insertOne && op . insertOne . document ) {
331- if ( op . insertOne . document . _id == null ) op . insertOne . document . _id = new ObjectID ( ) ;
331+ if ( forceServerObjectId !== true && op . insertOne . document . _id == null ) op . insertOne . document . _id = new ObjectID ( ) ;
332332 return addToOperationsList ( this , common . INSERT , op . insertOne . document ) ;
333333 }
334334
335335 if ( op . insertMany ) {
336336 for ( var i = 0 ; i < op . insertMany . length ; i ++ ) {
337- if ( op . insertMany [ i ] . _id == null ) op . insertMany [ i ] . _id = new ObjectID ( ) ;
337+ if ( forceServerObjectId !== true && op . insertMany [ i ] . _id == null ) op . insertMany [ i ] . _id = new ObjectID ( ) ;
338338 addToOperationsList ( this , common . INSERT , op . insertMany [ i ] ) ;
339339 }
340340
@@ -353,7 +353,7 @@ OrderedBulkOperation.prototype.raw = function(op) {
353353 * @return {OrderedBulkOperation }
354354 */
355355OrderedBulkOperation . prototype . insert = function ( document ) {
356- if ( document . _id == null ) document . _id = new ObjectID ( ) ;
356+ if ( this . s . collection . s . db . options . forceServerObjectId !== true && document . _id == null ) document . _id = new ObjectID ( ) ;
357357 return addToOperationsList ( this , common . INSERT , document ) ;
358358}
359359
0 commit comments