|
"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 }
|