@@ -45,12 +45,12 @@ const group = require('./operations/collection_ops').group;
45
45
const indexes = require ( './operations/collection_ops' ) . indexes ;
46
46
const indexExists = require ( './operations/collection_ops' ) . indexExists ;
47
47
const indexInformation = require ( './operations/collection_ops' ) . indexInformation ;
48
+ const insertMany = require ( './operations/collection_ops' ) . insertMany ;
48
49
const insertOne = require ( './operations/collection_ops' ) . insertOne ;
49
50
const isCapped = require ( './operations/collection_ops' ) . isCapped ;
50
51
const mapReduce = require ( './operations/collection_ops' ) . mapReduce ;
51
52
const optionsOp = require ( './operations/collection_ops' ) . optionsOp ;
52
53
const parallelCollectionScan = require ( './operations/collection_ops' ) . parallelCollectionScan ;
53
- const prepareDocs = require ( './operations/collection_ops' ) . prepareDocs ;
54
54
const reIndex = require ( './operations/collection_ops' ) . reIndex ;
55
55
const removeDocuments = require ( './operations/collection_ops' ) . removeDocuments ;
56
56
const rename = require ( './operations/collection_ops' ) . rename ;
@@ -463,21 +463,6 @@ Collection.prototype.insertOne = function(doc, options, callback) {
463
463
return executeOperation ( this . s . topology , insertOne , [ this , doc , options , callback ] ) ;
464
464
} ;
465
465
466
- function mapInsertManyResults ( docs , r ) {
467
- const finalResult = {
468
- result : { ok : 1 , n : r . insertedCount } ,
469
- ops : docs ,
470
- insertedCount : r . insertedCount ,
471
- insertedIds : r . insertedIds
472
- } ;
473
-
474
- if ( r . getLastOp ( ) ) {
475
- finalResult . result . opTime = r . getLastOp ( ) ;
476
- }
477
-
478
- return finalResult ;
479
- }
480
-
481
466
/**
482
467
* Inserts an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
483
468
* one will be added to each of the documents missing it by the driver, mutating the document. This behavior
@@ -501,33 +486,7 @@ Collection.prototype.insertMany = function(docs, options, callback) {
501
486
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
502
487
options = options ? Object . assign ( { } , options ) : { ordered : true } ;
503
488
504
- if ( ! Array . isArray ( docs ) && typeof callback === 'function' ) {
505
- return callback (
506
- MongoError . create ( { message : 'docs parameter must be an array of documents' , driver : true } )
507
- ) ;
508
- } else if ( ! Array . isArray ( docs ) ) {
509
- return new this . s . promiseLibrary ( ( resolve , reject ) => {
510
- reject (
511
- MongoError . create ( { message : 'docs parameter must be an array of documents' , driver : true } )
512
- ) ;
513
- } ) ;
514
- }
515
-
516
- // If keep going set unordered
517
- options [ 'serializeFunctions' ] = options [ 'serializeFunctions' ] || this . s . serializeFunctions ;
518
-
519
- docs = prepareDocs ( this , docs , options ) ;
520
-
521
- // Generate the bulk write operations
522
- const operations = [
523
- {
524
- insertMany : docs
525
- }
526
- ] ;
527
-
528
- return executeOperation ( this . s . topology , bulkWrite , [ this , operations , options , callback ] , {
529
- resultMutator : result => mapInsertManyResults ( docs , result )
530
- } ) ;
489
+ return executeOperation ( this . s . topology , insertMany , [ this , docs , options , callback ] ) ;
531
490
} ;
532
491
533
492
/**
0 commit comments