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

Mongosh is not throwing error when trying to drop a non-primary index

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.3.3
    • Affects Version/s: None
    • Component/s: None
    • Environment:
      OS:
      node.js / npm versions:
      Additional info:
    • Developer Tools
    • 2
    • Not Needed

      Problem Statement/Rationale

      When users run something like:

      test> response = db.test.dropIndex({"_id": 1});
      MongoServerError: cannot drop _id index
      
      test> console.info(response);
      ReferenceError: response is not defined 
      
      test> response = db.test.dropIndex({"a": 1});
      MongoshInternalError: can't find index with key: { a: 1 }
      
      test> console.info(response);
      {
        ok: 0,
        errmsg: "can't find index with key: { a: 1 }",
        code: 27,
        codeName: 'IndexNotFound'
      }
      

      mongosh seems to throw the error here instead of the dropIndex request going to the server. Hence `response` variable doesn't end up being set.

      Steps to Reproduce

      Run a similar snippet to above in mongosh

      Expected Results

      mongosh should throw an exception when dropping an index fails regardless of the exact index.

      Actual Results

      mongosh returns an error-like object rather than throwing an exception.

      Additional Notes

      Slack convo here: https://mongodb.slack.com/archives/CUHC9R8J0/p1695675347231129

            Assignee:
            gagik.amaryan@mongodb.com Gagik Amaryan
            Reporter:
            gaurab.aryal@mongodb.com Gaurab Aryal
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: