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

      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: