We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent be269b1 commit 945e915Copy full SHA for 945e915
lib/bulk/common.js
@@ -5,6 +5,7 @@ const MongoError = require('../core').MongoError;
5
const ObjectID = require('../core').BSON.ObjectID;
6
const BSON = require('../core').BSON;
7
const MongoWriteConcernError = require('../core').MongoWriteConcernError;
8
+const emitWarningOnce = require('../utils').emitWarningOnce;
9
const toError = require('../utils').toError;
10
const handleCallback = require('../utils').handleCallback;
11
const applyRetryableWrites = require('../utils').applyRetryableWrites;
@@ -737,15 +738,19 @@ class FindOperators {
737
738
739
/**
740
* backwards compatability for deleteOne
741
+ * @deprecated
742
*/
743
removeOne() {
744
+ emitWarningOnce('bulk operation `removeOne` has been deprecated, please use `deleteOne`');
745
return this.deleteOne();
746
}
747
748
749
* backwards compatability for delete
750
751
752
remove() {
753
+ emitWarningOnce('bulk operation `remove` has been deprecated, please use `delete`');
754
return this.delete();
755
756
@@ -1041,6 +1046,9 @@ class BulkOperationBase {
1041
1046
1042
1047
1043
1048
if (op.insertMany) {
1049
+ emitWarningOnce(
1050
+ 'bulk operation `insertMany` has been deprecated; use multiple `insertOne` ops instead'
1051
+ );
1044
1052
for (let i = 0; i < op.insertMany.length; i++) {
1045
1053
if (forceServerObjectId !== true && op.insertMany[i]._id == null)
1054
op.insertMany[i]._id = new ObjectID();
lib/operations/insert_many.js
@@ -30,11 +30,7 @@ class InsertManyOperation extends OperationBase {
30
docs = prepareDocs(coll, docs, options);
31
32
// Generate the bulk write operations
33
- const operations = [
34
- {
35
- insertMany: docs
36
- }
37
- ];
+ const operations = docs.map(document => ({ insertOne: { document } }));
38
39
const bulkWriteOperation = new BulkWriteOperation(coll, operations, options);
40
test/functional/bulk.test.js
@@ -520,7 +520,7 @@ describe('Bulk', function() {
520
.find({ b: 1 })
521
.upsert()
522
.update({ b: 1 });
523
- bulk.find({ c: 1 }).remove();
+ bulk.find({ c: 1 }).delete();
524
525
bulk.execute({ w: 0 }, function(err, result) {
526
test.equal(null, err);
@@ -1027,7 +1027,7 @@ describe('Bulk', function() {
1027
1028
1029
1030
1031
1032
1033
test/functional/crud_api.test.js
@@ -363,7 +363,8 @@ describe('CRUD API', function() {
363
db.collection('t2_5').bulkWrite(
364
[
365
{ insertOne: { a: 1 } },
366
- { insertMany: [{ g: 1 }, { g: 2 }] },
+ { insertOne: { document: { g: 1 } } },
367
+ { insertOne: { document: { g: 2 } } },
368
{ updateOne: { q: { a: 2 }, u: { $set: { a: 2 } }, upsert: true } },
369
{ updateMany: { q: { a: 2 }, u: { $set: { a: 2 } }, upsert: true } },
370
{ deleteOne: { q: { c: 1 } } },
@@ -444,7 +445,8 @@ describe('CRUD API', function() {
444
445
db.collection('t2_7').bulkWrite(
446
447
448
449
450
451
452
test/functional/operation_example.test.js
@@ -8746,7 +8746,7 @@ describe('Operation Examples', function() {
8746
8747
.updateOne({ $set: { b: 2 } });
8748
batch.insert({ a: 3 });
8749
- batch.find({ a: 3 }).remove({ a: 3 });
+ batch.find({ a: 3 }).delete({ a: 3 });
8750
8751
// Execute the operations
8752
batch.execute(function(err, result) {
@@ -8814,7 +8814,7 @@ describe('Operation Examples', function() {
8814
8815
8816
8817
8818
8819
8820
test/functional/operation_generators_example.test.js
@@ -5851,7 +5851,7 @@ describe('Operation (Generators)', function() {
5851
5852
5853
5854
5855
5856
5857
var result = yield batch.execute();
@@ -5924,7 +5924,7 @@ describe('Operation (Generators)', function() {
5924
5925
5926
5927
5928
5929
5930
test/functional/operation_promises_example.test.js
@@ -6395,7 +6395,7 @@ describe('Operation (Promises)', function() {
6395
6396
6397
6398
6399
6400
6401
return batch.execute().then(function(result) {
@@ -6465,7 +6465,7 @@ describe('Operation (Promises)', function() {
6465
6466
6467
6468
6469
6470
6471
0 commit comments