Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1158

bulkWrite Promise incorrectly expects null response

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None

      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.

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            neillunn Neil Lunn
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: