Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-3565): Error for insertMany with partially empty array is unhelpful #3221

Merged
merged 14 commits into from May 5, 2022
4 changes: 4 additions & 0 deletions src/bulk/common.ts
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
kampofo marked this conversation as resolved.
Show resolved Hide resolved
import {
BSONSerializeOptions,
Document,
Expand Down Expand Up @@ -1133,6 +1134,9 @@ export abstract class BulkOperationBase {

/** Specifies a raw operation to perform in the bulk write. */
raw(op: AnyBulkWriteOperation): this {
if (!op) {
throw new MongoInvalidArgumentError('Cannot perform bulkwrite operation on undefined operation');
kampofo marked this conversation as resolved.
Show resolved Hide resolved
}
if ('insertOne' in op) {
const forceServerObjectId = shouldForceServerObjectId(this);
if (op.insertOne && op.insertOne.document == null) {
Expand Down
66 changes: 66 additions & 0 deletions test/integration/crud/bulk.test.js
Expand Up @@ -23,6 +23,72 @@ describe('Bulk', function () {
return setupDatabase(this.configuration);
});

context('ops tests', () => {
kampofo marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line no-restricted-properties
it.only('Should raise an error when attempting bulkwrite operation on undefined operation', function (done) {
var configuration = this.configuration;
const client = configuration.newClient();
const docs = [];
docs[1] = {}; // works for docs[0] = {}
// client.db('test').collection('test').insertMany(docs);
// client.close();

let error = null;
let result = null;

client
.connect()
.then(function (client) {
return client.db('test').collection('test').insertMany(docs);
})
.then(function (r) {
result = r;
})
.catch(function (err) {
console.log(err);
error = err;
})
.then(function () {
expect(result).to.not.exist;
test.ok(error);
console.log(error, 'KOBBY');
client.close(done);
});
});

// eslint-disable-next-line no-restricted-properties
it.only('Should not raise an error when attempting bulkwrite operation on undefined operation', function (done) {
var configuration = this.configuration;
const client = configuration.newClient();
const docs = [];
docs[0] = {}; // works for docs[0] = {}
// client.db('test').collection('test').insertMany(docs);
// client.close();

let error = null;
let result = null;

client
.connect()
.then(function (client) {
return client.db('test').collection('test').insertMany(docs);
})
.then(function (r) {
result = r;
})
.catch(function (err) {
console.log(err);
error = err;
})
.then(function () {
expect(error).to.not.exist;
console.log(result, 'KOBBY');
test.ok(result);
client.close(done);
});
});
});

context('promise tests', () => {
it('Should correctly execute unordered bulk operation in promise form', function (done) {
const configuration = this.configuration;
Expand Down