-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(Bulk): change BulkWriteError message to first item from writeErrors #2013
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -937,6 +937,60 @@ describe('Bulk', function() { | |
| } | ||
| }); | ||
|
|
||
| it('should provide descriptive error message for unordered batch with duplicate key errors on inserts', function(done) { | ||
| const configuration = this.configuration; | ||
| const client = configuration.newClient(configuration.writeConcernMax(), { | ||
| poolSize: 1 | ||
| }); | ||
|
|
||
| client.connect(function(err, client) { | ||
|
||
| const db = client.db(configuration.db); | ||
| const col = db.collection('err_batch_write_unordered_ops_legacy_6'); | ||
|
|
||
| // Add unique index on a field causing all inserts to fail | ||
| col.createIndexes( | ||
| [ | ||
| { | ||
| name: 'err_batch_write_unordered_ops_legacy_6', | ||
| key: { a: 1 }, | ||
| unique: true | ||
| } | ||
| ], | ||
| function(err) { | ||
| expect(err).to.not.exist; | ||
|
|
||
| // Initialize the unordered Batch | ||
| const batch = col.initializeUnorderedBulkOp(); | ||
|
|
||
| // Add some operations to be executed in order | ||
| batch.insert({ a: 1 }); | ||
| batch.insert({ a: 1 }); | ||
|
|
||
| // Execute the operations | ||
| batch.execute(configuration.writeConcernMax(), function(err, result) { | ||
| expect(err).to.exist; | ||
| expect(result).to.not.exist; | ||
|
|
||
| // Test basic settings | ||
| result = err.result; | ||
| expect(result.nInserted).to.equal(1); | ||
| expect(result.hasWriteErrors()).to.equal(true); | ||
| expect(result.getWriteErrorCount() === 1).to.equal(true); | ||
|
|
||
| // Individual error checking | ||
| const error = result.getWriteErrorAt(0); | ||
| expect(error.code === 11000).to.equal(true); | ||
| expect(error.errmsg).to.exist; | ||
| expect(err.message).to.equal(error.errmsg); | ||
|
|
||
| client.close(); | ||
|
||
| done(); | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| it( | ||
| 'should Correctly Execute Unordered Batch of with upserts causing duplicate key errors on updates', | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if
this.s.bulkResult.writeErrors[0]or itserrmsgdoesn't exist? Let's check that theerrmsgexists and use the defaultwrite operation failedmessage if not.