-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Component/s: None
Examples (3.1.9-pre 2015-10-06-nightly)
> 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" */ })
{ "ok" : 1 }
Note: unrecognized options are not preserved.
> 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" */ })
{ "ok" : 1 }
> db.runCommand( { "listCollections": 1, "filter": { "name": "collectionName" } })
{ "cursor" : { "id" : NumberLong(0), "ns" : "test.$cmd.listCollections", "firstBatch" : [ { "name" : "collectionName", "options" : { "validator" : { "fieldName" : { "$gte" : 1024 } } } } ] }, "ok" : 1 }
{ "ok" : 0, "errmsg" : "invalid validation level: brokenLevel", "code" : 2 } { "ok" : 0, "errmsg" : "invalid validation action: brokenAction", "code" : 2 }
{ "ok" : 0, "errmsg" : "$text is not allowed in collection validators", "code" : 72 } { "ok" : 0, "errmsg" : "unknown operator: $texts", "code" : 2 }
- depends on
-
RUBY-1055 support creating a collection with options
- Closed
-
CXX-720 Add document validation support to CreateCollectionOperation
- Closed
-
JAVA-2008 Add document validation support to CreateCollectionOperation
- Closed
-
PHPLIB-135 Create/modify collection helpers needs to support creating "validators"
- Closed
-
RUST-8 Create/modify collection helpers needs to support creating "validators"
- Closed
-
CSHARP-1439 Add document validation support to CreateCollectionOperation
- Closed
-
CXX-719 Add document validation support to CreateCollectionOperation
- Closed
- is related to
-
DRIVERS-250 Support bypassDocumentValidation
- Closed
- related to
-
CXX-725 Add a collMod helper that takes document validation rules
- Closed