Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1364

assert.commandWorked throws ReferenceError

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • 2

      Problem Statement/Rationale

      When using the mongocompat snippet, usage of the assert.commandWorked method results in a ReferenceError. This is due to the usage of WriteResult in _isWriteResultType.

      Steps to Reproduce

      One-liner (assuming mongocompat snippet is installed):

      mongosh --eval "snippet load-all" --eval "assert.commandWorked(Mongo().getDB('admin').runCommand({ping: 1}));
      

      Expected Results

      Output from the legacy shell:

      [test-evg-tools|✚1] ❯❯❯ mongo --eval "assert.commandWorked(Mongo().getDB('admin').runCommand({ping: 1}));"
      MongoDB shell version v4.2.23
      [...]
      { "ok" : 1 }
      

      Actual Results

      Output from mongosh:

      [test-evg-tools|✚1] ❯❯❯ mongosh --eval "snippet load-all" --eval "assert.commandWorked(Mongo().getDB('admin').runCommand({ping: 1}));"
      [...]
      Using Mongosh:		1.6.2
      
      [...]
      
      ReferenceError: WriteResult is not defined
      

      Additional Notes

      I wanted to create a pull request to fix this, but I found a couple of other issues:

      • The _isWriteResultType function uses BulkWriteError, which also doesn't exist anymore. There is a MongoBulkWriteError, but I'm not sure if that is intended to be a replacement for BulkWriteError
      • WriteResult is accessed in other cases as well (e.g. in assert.writeOk); I'd assume that those usages can be dropped as BulkWriteResult is handled directly below.
      • I don't know how to test with my modified version: before submitting a pull request, I'd rather test the code to ensure everything is working (there is a suspicion that I'll run into the next issue after fixing WriteResult). If someone could tell me how to test a locally modified snippet, I'd be glad to work on the issues and make sure the assertion methods work (at least the ones we use in drivers-evergreen-tools).

            Assignee:
            gaurab.aryal@mongodb.com Gaurab Aryal
            Reporter:
            andreas.braun@mongodb.com Andreas Braun
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: