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

createCollection succeeds but crashes the shell if the driver mis-validates the collection name

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.1.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      OS: Windows, MongoWebShell

    • Not Needed
    • Developer Tools

      I was playing around with createCollection.
      Firstly, I was working on my local mongodb. I ran the following code and the shell client threw a lot of code and terminated immediately.

       

      db.createCollection("a.");

      I started client again and re-run the same command and it says that -
      MongoServerError: Collection test.a. already exists.

      When I ran the same code on Mongo Web Shell, it also did the same. But I can see the code that was thrown (below are the last few lines)

       

      {{ FUNCTION_STATE_IDENTIFIER = "threw";\n } else throw err;\n } finally

      {\n if (FUNCTION_STATE_IDENTIFIER !== "threw") FUNCTION_STATE_IDENTIFIER = "returned";\n }

      \n }\n '),h=o.template.statement("\n let EXPRESSION_HOLDER_IDENTIFIER;"),f=o.template.statements('\n let FUNCTION_STATE_IDENTIFIER = "sync",\n SYNC_RETURN_VALUE_IDENTIFIER;\n\n const ASYNC_RETURN_VALUE_IDENTIFIER = (ASYNC_TRY_CATCH_WRAPPER)();\n\n if (FUNCTION_STATE_IDENTIFIER === "returned")\n return SYNC_RETURN_VALUE_IDENTIFIER;\n else if (FUNCTION_STATE_IDENTIFIER === "threw")\n throw SYNC_RETURN_VALUE_IDENTIFIER;\n FUNCTION_STATE_IDENTIFIER = "async";\n return MSP_IDENTIFIER(ASYNC_RETURN_VALUE_IDENTIFIER);\n '),m=o.template.expression("(\n ORIGINAL_SOURCE,\n EXPRESSION_HOLDER = NODE,\n ISP_IDENTIFIER(EXPRESSION_HOLDER) ? await EXPRESSION_HOLDER : EXPRESSION_HOLDER\n )",

      {allowAwaitOutsideFunction:!0}

      ),g=o.template.expression("\n ANSP_IDENTIFIER(NODE, ORIGINAL_SOURCE)\n "),y=o.template.statement("\n try

      {\n ORIGINAL_CODE;\n }

      catch (err)

      {\n throw err;\n }

      \n "),_=o.template.statement(String.raw`

      MongoInvalidArgumentError: Collection names must not start or end with '.'
      at t.checkCollectionName (/tmp/m/boxednode/mongosh/node-v16.20.1/out/Release/node:2:2674072)
      at new Collection (/tmp/m/boxednode/mongosh/node-v16.20.1/out/Release/node:2:2452002)
      at /tmp/m/boxednode/mongosh/node-v16.20.1/out/Release/node:2:2570867 at /tmp/m/boxednode/mongosh/node-v16.20.1/out/Release/node:2:2431876 at /tmp/m/boxednode/mongosh/node-v16.20.1/out/Release/node:2:2628362 at /tmp/m/boxednode/mongosh/node-v16.20.1/out/Release/node:2:2627307 at Connection.onMessage (/tmp/m/boxednode/mongosh/node-v16.20.1/out/Release/node:2:2422155)
      at MessageStream.<anonymous> (/tmp/m/boxednode/mongosh/node-v16.20.1/out/Release/node:2:2420014)
      at MessageStream.emit (node:events:513:28)
      at MessageStream.emit (node:domain:489:12) {
      [Symbol(errorLabels)]: Set(0) {}
      }}}

      To my surprise, the web shell got terminated and I could access the machine. Attached the screenshot

            Assignee:
            leroux.bodenstein@mongodb.com Le Roux Bodenstein
            Reporter:
            abhiatmnnit@gmail.com Abhishek Chaudhary
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: