-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(Bulk): change BulkWriteError message to first item from writeErrors #2013
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -937,68 +937,59 @@ describe('Bulk', function() { | |
} | ||
}); | ||
|
||
it( | ||
'should provide descriptive error message for Unordered Batch with duplicate key errors on updates', | ||
{ | ||
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } }, | ||
|
||
test: function(done) { | ||
const configuration = this.configuration; | ||
var client = configuration.newClient(configuration.writeConcernMax(), { | ||
poolSize: 1 | ||
}); | ||
|
||
client.connect(function(err, client) { | ||
var db = client.db(configuration.db); | ||
var col = db.collection('err_batch_write_unordered_ops_legacy_6'); | ||
|
||
// Write concern | ||
var writeConcern = configuration.writeConcernMax(); | ||
writeConcern.unique = true; | ||
writeConcern.sparse = false; | ||
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 | ||
}); | ||
|
||
// Add unique index on b field causing all updates to fail | ||
col.ensureIndex({ b: 1 }, writeConcern, function(err) { | ||
expect(err).to.not.exist; | ||
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 | ||
var batch = col.initializeUnorderedBulkOp(); | ||
// Initialize the unordered Batch | ||
const batch = col.initializeUnorderedBulkOp(); | ||
|
||
// Add some operations to be executed in order | ||
batch.insert({ a: 1 }); | ||
batch.find({ a: 1 }).update({ $set: { b: 1 } }); | ||
batch.insert({ b: 1 }); | ||
batch.insert({ b: 1 }); | ||
batch.insert({ b: 1 }); | ||
batch.insert({ b: 1 }); | ||
// 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; | ||
// 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(2); | ||
expect(result.hasWriteErrors()).to.equal(true); | ||
expect( | ||
result.getWriteErrorCount() === 4 || result.getWriteErrorCount() === 3 | ||
).to.equal(true); | ||
// 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 | ||
var error = result.getWriteErrorAt(0); | ||
expect(error.code === 11000 || error.code === 11001).to.equal(true); | ||
expect(error.errmsg).to.exist; | ||
expect(err.message).to.equal(error.errmsg); | ||
// 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(); | ||
}); | ||
client.close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change this to |
||
done(); | ||
}); | ||
}); | ||
} | ||
} | ||
); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
it( | ||
'should Correctly Execute Unordered Batch of with upserts causing duplicate key errors on updates', | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For all callbacks in this test, let's use
(err, client) => {
notation instead offunction(err, client) {
.