-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Empty show more show less
The current `bulkWrite()` implementation is expecting a null response from the underlying Bulk API when an error is returned in the callback form which is wrapped in a Promise to return. This check means that errors are being ignored and passed to `resolve(r)` rather than `reject(err)`. This is evident in the[ current code:|https://github.com/mongodb/node-mongodb-native/blob/2.2/lib/collection.js#L613-L619]:
// Return a Promise return new this.s.promiseLibrary(function(resolve, reject) { bulkWrite(self, operations, options, function(err, r) { if(err && r == null) return reject(err); resolve(r); }); });
Either the response should be set to `null` before reaching this code or he additional condition expecting it to be so is not valid.
See https://stackoverflow.com/q/46700461/2313887 for a reproducible case. It's a trivial one, but it is reproducible for any error in response. For consistency the `writeErrors` should be accessible from the thrown exception, with duplicate key errors on un-ordered operations being the most common case of inspection AFAIK.