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

Create command should reject incorrect types for known options

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.1.10
    • Component/s: Querying, Usability
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Storage NYC 2019-03-25, Storage NYC 2019-04-08

      Description

      Create command should reject incorrect types for known options. It's easy to accidentally provide the wrong types for a "create" option, like providing a string for "max":

      MongoDB Enterprise > db.createCollection("test", {capped:true, size:10, max:"10"})
      { "ok" : 1 }
      MongoDB Enterprise > db.getCollectionInfos()
      [
      	{
      		"name" : "test",
      		"type" : "collection",
      		"options" : {
      			"capped" : true,
      			"size" : 256
      		},
      ...
      

      Or forgetting the "capped" option but including "size" and "max":

      MongoDB Enterprise > db.createCollection("test2", {size:10, max:10})
      { "ok" : 1 }
      MongoDB Enterprise > db.getCollectionInfos()
      [
      	{
      		"name" : "test2",
      		"type" : "collection",
      		"options" : {
       
      		},
      ...
      

      In both of these cases, the server silently ignores some of the options and creates a collection that, almost certainly, is not what the user wanted. I think it would be an improvement for the "create" command to return an InvalidOptions error instead.

      This is semi-related to SERVER-25459 (Create command should reject unknown options) and SERVER-16069 (Input validation on the arguments to createCollection).

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: