Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-269

Create/modify collection helpers needs to support creating "validators"

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Component/s: None
    • Labels:
    • $i18n.getText("admin.common.words.hide")
      Key Status/Resolution FixVersion
      JAVA-2008 Done 3.2.0
      CSHARP-1439 Done 1.11, 2.2
      RUBY-1055 Done 2.2.0
      SCALA-219 Done 1.1.0
      CXX-719 Done
      CXX-720 Done 3.0.0-rc0
      PHPLIB-135 Done 1.0.0-beta2
      RUST-8 Fixed 1.1.0
      SWIFT-460 Done
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } Key Status/Resolution FixVersion JAVA-2008 Done 3.2.0 CSHARP-1439 Done 1.11, 2.2 RUBY-1055 Done 2.2.0 SCALA-219 Done 1.1.0 CXX-719 Done CXX-720 Done 3.0.0-rc0 PHPLIB-135 Done 1.0.0-beta2 RUST-8 Fixed 1.1.0 SWIFT-460 Done

      Examples (3.1.9-pre 2015-10-06-nightly)

      Setting up a validator for a collection
      "Creating a validator during collection creation"
      > db.runCommand(
      {
      	"create": "collectionName",
      	"validator": { /* $query document. (Almost) all $query operators allowed*/
      		"fieldName": {
      			"$gte": 1024
      		}
      	},
      	/* (default: "" == "strict") */
      	"validationLevel": "", /* "" | "strict" | "off" | "moderate" */
      	/*  (default: "" == "error") */
      	"validationAction": "" /* "" | "error" | "warn" */
      })
      
      "The above example will output:"
      { "ok" : 1 }
      

      Note: unrecognized options are not preserved.

      "Creating a validator on existing collection"
      > db.existingCollectionName.insert({"my": "document"})
      WriteResult({ "nInserted" : 1 })
      > db.runCommand(
      {
      	"collMod": "existingCollectionName",
      	"validator": { /* Same $query document as for the 'create' command */
      		"fieldName": {
      			"$gte": 1024
      		}
      	},
      	/* (default: "" == "strict") */
      	"validationLevel": "", /* "" | "strict" | "off" | "moderate" */
      	/*  (default: "" == "error") */
      	"validationAction": "" /* "" | "error" | "warn" */
      })
      
      "The above example will output:"
      { "ok" : 1 }
      



      "Verifying you validators were created/showing existing validators on a collection"
      "Showing validators for a collection"
      > db.runCommand(
      {
      	"listCollections": 1,
      	"filter": {
      		"name": "collectionName"
      	}
      })
      
      "The above example will output:"
      {
      	"cursor" : {
      		"id" : NumberLong(0),
      		"ns" : "test.$cmd.listCollections",
      		"firstBatch" : [
      			{
      				"name" : "collectionName",
      				"options" : {
      					"validator" : {
      						"fieldName" : {
      							"$gte" : 1024
      						}
      					}
      				}
      			}
      		]
      	},
      	"ok" : 1
      }
      



      "Errors"
      "Invalid validationLevel or validationAction"
      { "ok" : 0, "errmsg" : "invalid validation level: brokenLevel", "code" : 2 }
      { "ok" : 0, "errmsg" : "invalid validation action: brokenAction", "code" : 2 }
      
      "Using illegal operators"
      {
      	"ok" : 0,
      	"errmsg" : "$text is not allowed in collection validators",
      	"code" : 72
      }
      { "ok" : 0, "errmsg" : "unknown operator: $texts", "code" : 2 }
      

            Assignee:
            barrie Barrie Segal
            Reporter:
            rathi.gnanasekaran Rathi Gnanasekaran
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: