Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-64078

Missing ErrMsg for Multiple Bulk Write Errors

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • ALL
    • Hide
      • Install PyMongo 4+ and Mongo Latest in Evergreen
      • Run the code above
      Show
      Install PyMongo 4+ and Mongo Latest in Evergreen Run the code above
    • Sharding EMEA 2022-03-07

      The following code shows the appropriate error messages when used with Mongo 5.2:

        >>> from pymongo import InsertOne, DeleteOne, ReplaceOne
        >>> from pymongo.errors import BulkWriteError
        >>> requests = [
        ...     InsertOne({'_id': 1}),
        ...     DeleteOne({'_id': 2}),
        ...     InsertOne({'_id': 3}),
        ...     ReplaceOne({'_id': 4}, {'i': 1})]
        >>> try:
        ...     db.test.bulk_write(requests, ordered=False)
        ... except BulkWriteError as bwe:
        ...     pprint(bwe.details)
          {'nInserted': 0,
           'nMatched': 1,
           'nModified': 1,
           'nRemoved': 1,
           'nUpserted': 0,
           'upserted': [],
           'writeConcernErrors': [],
           'writeErrors': [{'code': 11000,
                            'errmsg': 'E11000 duplicate key error collection: '
                                      'bulk_example.test index: _id_ dup key: { _id: 1 }',
                            'index': 0,
                            'keyPattern': {'_id': 1},
                            'keyValue': {'_id': 1},
                            'op': {'_id': 1}},
                           {'code': 11000,
                            'errmsg': 'E11000 duplicate key error collection: '
                                      'bulk_example.test index: _id_ dup key: { _id: 3 }',
                            'index': 2,
                            'keyPattern': {'_id': 1},
                            'keyValue': {'_id': 3},
                            'op': {'_id': 3}}]}
      

      When using Mongo Latest in Evergreen, we get the following output (note the empty errmsg in the second error object):

          {'nInserted': 0,
           'nMatched': 1,
           'nModified': 1,
           'nRemoved': 1,
           'nUpserted': 0,
           'upserted': [],
           'writeConcernErrors': [],
           'writeErrors': [{'code': 11000,
                            'errmsg': 'E11000 duplicate key error collection: '
                                      'bulk_example.test index: _id_ dup key: { _id: 1 }',
                            'index': 0,
                            'keyPattern': {'_id': 1},
                            'keyValue': {'_id': 1},
                            'op': {'_id': 1}},
                           {'code': 11000,
                            'errmsg': '',
                            'index': 2,
                            'keyPattern': {'_id': 1},
                            'keyValue': {'_id': 3},
                            'op': {'_id': 3}}]}
      

            Assignee:
            kaloian.manassiev@mongodb.com Kaloian Manassiev
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: