Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
None
Description
Examples (3.1.9-pre 2015-10-06-nightly)
|
"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 } |
|
"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 |
}
|
|
"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
- 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
-