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

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

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: Public
    • Labels:
    • # Replies:
      5
    • Last comment by Customer:
      false
    • SERVER fixVersion:
      3.2

      Description

      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 }
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Days since reply:
                4 years, 37 weeks, 4 days ago
                Date of 1st Reply: