diff --git a/lib/bulk/common.js b/lib/bulk/common.js index 83a719a382..c99c876959 100644 --- a/lib/bulk/common.js +++ b/lib/bulk/common.js @@ -5,6 +5,7 @@ const MongoError = require('../core').MongoError; const ObjectID = require('../core').BSON.ObjectID; const BSON = require('../core').BSON; const MongoWriteConcernError = require('../core').MongoWriteConcernError; +const emitWarningOnce = require('../utils').emitWarningOnce; const toError = require('../utils').toError; const handleCallback = require('../utils').handleCallback; const applyRetryableWrites = require('../utils').applyRetryableWrites; @@ -737,15 +738,19 @@ class FindOperators { /** * backwards compatability for deleteOne + * @deprecated */ removeOne() { + emitWarningOnce('bulk operation `removeOne` has been deprecated, please use `deleteOne`'); return this.deleteOne(); } /** * backwards compatability for delete + * @deprecated */ remove() { + emitWarningOnce('bulk operation `remove` has been deprecated, please use `delete`'); return this.delete(); } } @@ -1041,6 +1046,9 @@ class BulkOperationBase { } if (op.insertMany) { + emitWarningOnce( + 'bulk operation `insertMany` has been deprecated; use multiple `insertOne` ops instead' + ); for (let i = 0; i < op.insertMany.length; i++) { if (forceServerObjectId !== true && op.insertMany[i]._id == null) op.insertMany[i]._id = new ObjectID(); diff --git a/lib/operations/insert_many.js b/lib/operations/insert_many.js index 460a535d66..fdfc0d46bb 100644 --- a/lib/operations/insert_many.js +++ b/lib/operations/insert_many.js @@ -30,11 +30,7 @@ class InsertManyOperation extends OperationBase { docs = prepareDocs(coll, docs, options); // Generate the bulk write operations - const operations = [ - { - insertMany: docs - } - ]; + const operations = docs.map(document => ({ insertOne: { document } })); const bulkWriteOperation = new BulkWriteOperation(coll, operations, options); diff --git a/test/functional/bulk.test.js b/test/functional/bulk.test.js index ced20b1f36..7187425d81 100644 --- a/test/functional/bulk.test.js +++ b/test/functional/bulk.test.js @@ -520,7 +520,7 @@ describe('Bulk', function() { .find({ b: 1 }) .upsert() .update({ b: 1 }); - bulk.find({ c: 1 }).remove(); + bulk.find({ c: 1 }).delete(); bulk.execute({ w: 0 }, function(err, result) { test.equal(null, err); @@ -1027,7 +1027,7 @@ describe('Bulk', function() { .find({ b: 1 }) .upsert() .update({ b: 1 }); - bulk.find({ c: 1 }).remove(); + bulk.find({ c: 1 }).delete(); bulk.execute({ w: 0 }, function(err, result) { test.equal(null, err); diff --git a/test/functional/crud_api.test.js b/test/functional/crud_api.test.js index 3908fd46ff..5f2051af93 100644 --- a/test/functional/crud_api.test.js +++ b/test/functional/crud_api.test.js @@ -363,7 +363,8 @@ describe('CRUD API', function() { db.collection('t2_5').bulkWrite( [ { insertOne: { a: 1 } }, - { insertMany: [{ g: 1 }, { g: 2 }] }, + { insertOne: { document: { g: 1 } } }, + { insertOne: { document: { g: 2 } } }, { updateOne: { q: { a: 2 }, u: { $set: { a: 2 } }, upsert: true } }, { updateMany: { q: { a: 2 }, u: { $set: { a: 2 } }, upsert: true } }, { deleteOne: { q: { c: 1 } } }, @@ -444,7 +445,8 @@ describe('CRUD API', function() { db.collection('t2_7').bulkWrite( [ { insertOne: { a: 1 } }, - { insertMany: [{ g: 1 }, { g: 2 }] }, + { insertOne: { document: { g: 1 } } }, + { insertOne: { document: { g: 2 } } }, { updateOne: { q: { a: 2 }, u: { $set: { a: 2 } }, upsert: true } }, { updateMany: { q: { a: 2 }, u: { $set: { a: 2 } }, upsert: true } }, { deleteOne: { q: { c: 1 } } }, diff --git a/test/functional/operation_example.test.js b/test/functional/operation_example.test.js index a4db0658de..001e6d8a09 100644 --- a/test/functional/operation_example.test.js +++ b/test/functional/operation_example.test.js @@ -8746,7 +8746,7 @@ describe('Operation Examples', function() { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations batch.execute(function(err, result) { @@ -8814,7 +8814,7 @@ describe('Operation Examples', function() { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations batch.execute(function(err, result) { diff --git a/test/functional/operation_generators_example.test.js b/test/functional/operation_generators_example.test.js index 8054e44672..f1a9cd596a 100644 --- a/test/functional/operation_generators_example.test.js +++ b/test/functional/operation_generators_example.test.js @@ -5851,7 +5851,7 @@ describe('Operation (Generators)', function() { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations var result = yield batch.execute(); @@ -5924,7 +5924,7 @@ describe('Operation (Generators)', function() { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations var result = yield batch.execute(); diff --git a/test/functional/operation_promises_example.test.js b/test/functional/operation_promises_example.test.js index 71a0e0424e..2f3bbad32e 100644 --- a/test/functional/operation_promises_example.test.js +++ b/test/functional/operation_promises_example.test.js @@ -6395,7 +6395,7 @@ describe('Operation (Promises)', function() { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations return batch.execute().then(function(result) { @@ -6465,7 +6465,7 @@ describe('Operation (Promises)', function() { .upsert() .updateOne({ $set: { b: 2 } }); batch.insert({ a: 3 }); - batch.find({ a: 3 }).remove({ a: 3 }); + batch.find({ a: 3 }).delete({ a: 3 }); // Execute the operations return batch.execute().then(function(result) {